From bf3bf836ac65800f2d319699121794f6973483d4 Mon Sep 17 00:00:00 2001 From: Redkale Date: Tue, 10 Jan 2023 20:41:20 +0800 Subject: [PATCH] =?UTF-8?q?AsyncConnection=E5=A2=9E=E5=8A=A0writeInIOThrea?= =?UTF-8?q?d=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/redkale/net/AsyncConnection.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) 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");