Due to the recent changes with AsynchronousChannelGroup use, there's no

need to schedule read operation later.
This commit is contained in:
Trustin Lee 2012-07-09 00:04:55 +09:00
parent ee019d344e
commit a58533fdad

View File

@ -49,22 +49,6 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
} }
} }
private final Runnable readTask = new Runnable() {
@Override
public void run() {
ByteBuf byteBuf = pipeline().inboundByteBuffer();
if (!byteBuf.readable()) {
byteBuf.clear();
} else {
expandReadBuffer(byteBuf);
}
// Get a ByteBuffer view on the ByteBuf
ByteBuffer buffer = byteBuf.nioBuffer(byteBuf.writerIndex(), byteBuf.writableBytes());
javaChannel().read(buffer, AioSocketChannel.this, READ_HANDLER);
}
};
private final AioSocketChannelConfig config; private final AioSocketChannelConfig config;
private boolean flushing; private boolean flushing;
@ -130,7 +114,12 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
return null; return null;
} }
return readTask; return new Runnable() {
@Override
public void run() {
beginRead();
}
};
} }
private static boolean expandReadBuffer(ByteBuf byteBuf) { private static boolean expandReadBuffer(ByteBuf byteBuf) {
@ -176,6 +165,19 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
} }
} }
private void beginRead() {
ByteBuf byteBuf = pipeline().inboundByteBuffer();
if (!byteBuf.readable()) {
byteBuf.clear();
} else {
expandReadBuffer(byteBuf);
}
// Get a ByteBuffer view on the ByteBuf
ByteBuffer buffer = byteBuf.nioBuffer(byteBuf.writerIndex(), byteBuf.writableBytes());
javaChannel().read(buffer, AioSocketChannel.this, READ_HANDLER);
}
private static final class WriteHandler extends AioCompletionHandler<Integer, AioSocketChannel> { private static final class WriteHandler extends AioCompletionHandler<Integer, AioSocketChannel> {
@Override @Override
@ -275,7 +277,7 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
channel.unsafe().close(channel.unsafe().voidFuture()); channel.unsafe().close(channel.unsafe().voidFuture());
} else { } else {
// start the next read // start the next read
channel.eventLoop().execute(channel.readTask); channel.beginRead();
} }
} }
} }
@ -292,7 +294,7 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
channel.unsafe().close(channel.unsafe().voidFuture()); channel.unsafe().close(channel.unsafe().voidFuture());
} else { } else {
// start the next read // start the next read
channel.eventLoop().execute(channel.readTask); channel.beginRead();
} }
} }
} }
@ -301,7 +303,7 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
@Override @Override
protected void completed0(Void result, AioSocketChannel channel) { protected void completed0(Void result, AioSocketChannel channel) {
channel.readTask.run(); channel.beginRead();
((AsyncUnsafe) channel.unsafe()).connectSuccess(); ((AsyncUnsafe) channel.unsafe()).connectSuccess();
channel.pipeline().fireChannelActive(); channel.pipeline().fireChannelActive();
} }