diff --git a/src/main/java/org/redkale/net/AsyncConnection.java b/src/main/java/org/redkale/net/AsyncConnection.java index b9c1f896b..1c74a87f9 100644 --- a/src/main/java/org/redkale/net/AsyncConnection.java +++ b/src/main/java/org/redkale/net/AsyncConnection.java @@ -361,7 +361,6 @@ public abstract class AsyncConnection implements Channel, AutoCloseable { } } - // srcs写完才会回调 public final void write( ByteBuffer[] srcs, int offset, int length, A attachment, CompletionHandler handler) { if (sslEngine == null) { @@ -382,7 +381,6 @@ public abstract class AsyncConnection implements Channel, AutoCloseable { } } - // srcs写完才会回调 public final void write(ByteBuffer[] srcs, A attachment, CompletionHandler handler) { write(srcs, 0, srcs.length, attachment, handler); } @@ -493,7 +491,6 @@ public abstract class AsyncConnection implements Channel, AutoCloseable { } } - // srcs写完才会回调 public final void writeInIOThread( ByteBuffer[] srcs, int offset, int length, A attachment, CompletionHandler handler) { if (inCurrWriteThread()) { @@ -503,7 +500,6 @@ public abstract class AsyncConnection implements Channel, AutoCloseable { } } - // srcs写完才会回调 public final void writeInIOThread( ByteBuffer[] srcs, A attachment, CompletionHandler handler) { if (inCurrWriteThread()) { @@ -513,7 +509,6 @@ public abstract class AsyncConnection implements Channel, AutoCloseable { } } - // srcs写完才会回调 public final void writeInIOThread(byte[] bytes, CompletionHandler handler) { if (inCurrWriteThread()) { write(bytes, handler); @@ -522,7 +517,6 @@ public abstract class AsyncConnection implements Channel, AutoCloseable { } } - // srcs写完才会回调 public final void writeInIOThread(ByteTuple array, CompletionHandler handler) { if (inCurrWriteThread()) { write(array, handler); @@ -531,7 +525,6 @@ public abstract class AsyncConnection implements Channel, AutoCloseable { } } - // srcs写完才会回调 public final void writeInIOThread(byte[] bytes, int offset, int length, CompletionHandler handler) { if (inCurrWriteThread()) { write(bytes, offset, length, handler); @@ -540,7 +533,6 @@ public abstract class AsyncConnection implements Channel, AutoCloseable { } } - // srcs写完才会回调 public final void writeInIOThread(ByteTuple header, ByteTuple body, CompletionHandler handler) { if (inCurrWriteThread()) { write(header, body, handler); @@ -549,7 +541,6 @@ public abstract class AsyncConnection implements Channel, AutoCloseable { } } - // srcs写完才会回调 public final void writeInIOThread( byte[] headerContent, int headerOffset, @@ -566,6 +557,61 @@ public abstract class AsyncConnection implements Channel, AutoCloseable { } } + public final void writeInLock(ByteBuffer[] srcs, A attachment, CompletionHandler handler) { + writeInLock(srcs, 0, srcs.length, attachment, handler); + } + + public final void writeInLock(byte[] bytes, CompletionHandler handler) { + writeInLock(ByteBuffer.wrap(bytes), null, handler); + } + + public final void writeInLock(ByteTuple array, CompletionHandler handler) { + writeInLock(ByteBuffer.wrap(array.content(), array.offset(), array.length()), null, handler); + } + + public final void writeInLock(byte[] bytes, int offset, int length, CompletionHandler handler) { + writeInLock(ByteBuffer.wrap(bytes, offset, length), null, handler); + } + + public final void writeInLock(ByteTuple header, ByteTuple body, CompletionHandler handler) { + if (body == null) { + writeInLock(ByteBuffer.wrap(header.content(), header.offset(), header.length()), null, handler); + } else if (header == null) { + writeInLock(ByteBuffer.wrap(body.content(), body.offset(), body.length()), null, handler); + } else { + writeInLock( + new ByteBuffer[] { + ByteBuffer.wrap(header.content(), header.offset(), header.length()), + ByteBuffer.wrap(body.content(), body.offset(), body.length()) + }, + null, + handler); + } + } + + public final void writeInLock( + byte[] headerContent, + int headerOffset, + int headerLength, + byte[] bodyContent, + int bodyOffset, + int bodyLength, + CompletionHandler handler) { + if (bodyContent == null) { + writeInLock(ByteBuffer.wrap(headerContent, headerOffset, headerLength), null, handler); + } else if (headerContent == null) { + writeInLock(ByteBuffer.wrap(bodyContent, bodyOffset, bodyLength), null, handler); + } else { + writeInLock( + new ByteBuffer[] { + ByteBuffer.wrap(headerContent, headerOffset, headerLength), + ByteBuffer.wrap(bodyContent, bodyOffset, bodyLength) + }, + null, + handler); + } + } + public void setReadBuffer(ByteBuffer buffer) { if (this.readBuffer != null) { throw new RedkaleException("repeat AsyncConnection.setReadBuffer");