Reduced unnecessary duplicate calls on NioSocketChannel

This commit is contained in:
Trustin Lee 2010-01-29 02:59:40 +00:00
parent eed6e6cc3a
commit 9b1d9b0c61

View File

@ -24,7 +24,6 @@ import java.nio.channels.AsynchronousCloseException;
import java.nio.channels.CancelledKeyException; import java.nio.channels.CancelledKeyException;
import java.nio.channels.ClosedChannelException; import java.nio.channels.ClosedChannelException;
import java.nio.channels.NotYetConnectedException; import java.nio.channels.NotYetConnectedException;
import java.nio.channels.ScatteringByteChannel;
import java.nio.channels.SelectionKey; import java.nio.channels.SelectionKey;
import java.nio.channels.Selector; import java.nio.channels.Selector;
import java.util.Iterator; import java.util.Iterator;
@ -303,17 +302,15 @@ class NioWorker implements Runnable {
} }
private boolean read(SelectionKey k) { private boolean read(SelectionKey k) {
ScatteringByteChannel ch = (ScatteringByteChannel) k.channel(); final java.nio.channels.SocketChannel nioch =
NioSocketChannel channel = (NioSocketChannel) k.attachment(); (java.nio.channels.SocketChannel) k.channel();
final NioSocketChannel channel = (NioSocketChannel) k.attachment();
ReceiveBufferSizePredictor predictor = final NioSocketChannelConfig cfg = channel.getConfig();
channel.getConfig().getReceiveBufferSizePredictor(); final ReceiveBufferSizePredictor predictor = cfg.getReceiveBufferSizePredictor();
ChannelBufferFactory bufferFactory = final ChannelBufferFactory bufferFactory = cfg.getBufferFactory();
channel.getConfig().getBufferFactory();
ChannelBuffer buffer =
bufferFactory.getBuffer(predictor.nextReceiveBufferSize());
final ChannelBuffer buffer = bufferFactory.getBuffer(predictor.nextReceiveBufferSize());
final ByteBuffer directBuffer; final ByteBuffer directBuffer;
final boolean fromPool = !buffer.isDirect(); final boolean fromPool = !buffer.isDirect();
if (fromPool) { if (fromPool) {
@ -326,7 +323,7 @@ class NioWorker implements Runnable {
int readBytes = 0; int readBytes = 0;
boolean failure = true; boolean failure = true;
try { try {
while ((ret = ch.read(directBuffer)) > 0) { while ((ret = nioch.read(directBuffer)) > 0) {
readBytes += ret; readBytes += ret;
if (!directBuffer.hasRemaining()) { if (!directBuffer.hasRemaining()) {
break; break;