diff --git a/src/org/redkale/net/TcpNioAsyncConnection.java b/src/org/redkale/net/TcpNioAsyncConnection.java index fb3f0310a..4ca9dff39 100644 --- a/src/org/redkale/net/TcpNioAsyncConnection.java +++ b/src/org/redkale/net/TcpNioAsyncConnection.java @@ -223,7 +223,6 @@ public class TcpNioAsyncConnection extends AsyncConnection { return; } this.readPending = true; - this.readByteBuffer = pollReadBuffer(); if (this.readTimeoutSeconds > 0) { NioCompletionHandler newhandler = new NioCompletionHandler(handler, this.readByteBuffer); this.readCompletionHandler = newhandler; @@ -380,6 +379,12 @@ public class TcpNioAsyncConnection extends AsyncConnection { final boolean invokeDirect = this.ioThread.inSameThread(); int totalCount = 0; boolean hasRemain = true; + if (invokeDirect && this.readByteBuffer == null) { + this.readByteBuffer = pollReadBuffer(); + if (this.readTimeoutSeconds > 0) { + ((NioCompletionHandler) this.readCompletionHandler).setAttachment(this.readByteBuffer); + } + } while (invokeDirect && hasRemain) { int readCount = this.channel.read(readByteBuffer); hasRemain = readByteBuffer.hasRemaining(); diff --git a/src/org/redkale/net/nio/NioCompletionHandler.java b/src/org/redkale/net/nio/NioCompletionHandler.java index 7a6c8fb78..f30b7e1f9 100644 --- a/src/org/redkale/net/nio/NioCompletionHandler.java +++ b/src/org/redkale/net/nio/NioCompletionHandler.java @@ -21,7 +21,7 @@ public class NioCompletionHandler implements CompletionHandler, R private final CompletionHandler handler; - private final A attachment; + private A attachment; public ScheduledFuture timeoutFuture; @@ -30,6 +30,10 @@ public class NioCompletionHandler implements CompletionHandler, R this.attachment = attachment; } + public void setAttachment(A attachment) { + this.attachment = attachment; + } + @Override public void completed(Integer result, A attach) { ScheduledFuture future = this.timeoutFuture;