This commit is contained in:
Redkale
2020-06-30 19:30:53 +08:00
parent 2e66b1a546
commit c93c1d84c5
2 changed files with 11 additions and 2 deletions

View File

@@ -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();

View File

@@ -21,7 +21,7 @@ public class NioCompletionHandler<A> implements CompletionHandler<Integer, A>, R
private final CompletionHandler<Integer, A> handler;
private final A attachment;
private A attachment;
public ScheduledFuture timeoutFuture;
@@ -30,6 +30,10 @@ public class NioCompletionHandler<A> implements CompletionHandler<Integer, A>, R
this.attachment = attachment;
}
public void setAttachment(A attachment) {
this.attachment = attachment;
}
@Override
public void completed(Integer result, A attach) {
ScheduledFuture future = this.timeoutFuture;