diff --git a/src/main/java/org/redkale/net/AsyncConnection.java b/src/main/java/org/redkale/net/AsyncConnection.java index e9857ae4f..895e855ee 100644 --- a/src/main/java/org/redkale/net/AsyncConnection.java +++ b/src/main/java/org/redkale/net/AsyncConnection.java @@ -361,6 +361,73 @@ public abstract class AsyncConnection implements ChannelContext, Channel, AutoCl } } + //src写完才会回调 + public final void writeInIOThread(ByteBuffer src, A attachment, CompletionHandler handler) { + if (inCurrWriteThread()) { + write(src, attachment, handler); + } else { + executeWrite(() -> write(src, attachment, handler)); + } + } + + //srcs写完才会回调 + public final void writeInIOThread(ByteBuffer[] srcs, int offset, int length, A attachment, CompletionHandler handler) { + if (inCurrWriteThread()) { + write(srcs, offset, length, attachment, handler); + } else { + executeWrite(() -> write(srcs, offset, length, attachment, handler)); + } + } + + //srcs写完才会回调 + public final void writeInIOThread(ByteBuffer[] srcs, A attachment, CompletionHandler handler) { + if (inCurrWriteThread()) { + write(srcs, attachment, handler); + } else { + executeWrite(() -> write(srcs, attachment, handler)); + } + } + + public final void writeInIOThread(byte[] bytes, CompletionHandler handler) { + if (inCurrWriteThread()) { + write(bytes, handler); + } else { + executeWrite(() -> write(bytes, handler)); + } + } + + public final void writeInIOThread(ByteTuple array, CompletionHandler handler) { + if (inCurrWriteThread()) { + write(array, handler); + } else { + executeWrite(() -> write(array, handler)); + } + } + + public final void writeInIOThread(byte[] bytes, int offset, int length, CompletionHandler handler) { + if (inCurrWriteThread()) { + write(bytes, offset, length, handler); + } else { + executeWrite(() -> write(bytes, offset, length, handler)); + } + } + + public final void writeInIOThread(ByteTuple header, ByteTuple body, CompletionHandler handler) { + if (inCurrWriteThread()) { + write(header, body, handler); + } else { + executeWrite(() -> write(header, body, handler)); + } + } + + public final void writeInIOThread(byte[] headerContent, int headerOffset, int headerLength, byte[] bodyContent, int bodyOffset, int bodyLength, Consumer bodyCallback, Object bodyAttachment, CompletionHandler handler) { + if (inCurrWriteThread()) { + write(headerContent, headerOffset, headerLength, bodyContent, bodyOffset, bodyLength, bodyCallback, bodyAttachment, handler); + } else { + executeWrite(() -> write(headerContent, headerOffset, headerLength, bodyContent, bodyOffset, bodyLength, bodyCallback, bodyAttachment, handler)); + } + } + public void setReadBuffer(ByteBuffer buffer) { if (this.readBuffer != null) { throw new RuntimeException("repeat AsyncConnection.setReadBuffer");