Reduced unnecessary duplicate calls on NioSocketChannel
This commit is contained in:
parent
eed6e6cc3a
commit
9b1d9b0c61
@ -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;
|
||||||
@ -379,13 +376,13 @@ class NioWorker implements Runnable {
|
|||||||
cleanUpWriteBuffer(channel);
|
cleanUpWriteBuffer(channel);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ReentrantLock writeLock = channel.writeLock;
|
final ReentrantLock writeLock = channel.writeLock;
|
||||||
if (writeLock.isHeldByCurrentThread() || !writeLock.tryLock()) {
|
if (writeLock.isHeldByCurrentThread() || !writeLock.tryLock()) {
|
||||||
rescheduleWrite(channel);
|
rescheduleWrite(channel);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Queue<MessageEvent> writeBuffer = channel.writeBuffer;
|
final Queue<MessageEvent> writeBuffer = channel.writeBuffer;
|
||||||
final int writeSpinCount = channel.getConfig().getWriteSpinCount();
|
final int writeSpinCount = channel.getConfig().getWriteSpinCount();
|
||||||
|
|
||||||
@ -646,7 +643,7 @@ class NioWorker implements Runnable {
|
|||||||
channel.setRawInterestOpsNow(interestOps);
|
channel.setRawInterestOpsNow(interestOps);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (CONSTRAINT_LEVEL) {
|
switch (CONSTRAINT_LEVEL) {
|
||||||
case 0:
|
case 0:
|
||||||
if (channel.getRawInterestOps() != interestOps) {
|
if (channel.getRawInterestOps() != interestOps) {
|
||||||
@ -686,7 +683,7 @@ class NioWorker implements Runnable {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class RegisterTask implements Runnable {
|
private final class RegisterTask implements Runnable {
|
||||||
private final NioSocketChannel channel;
|
private final NioSocketChannel channel;
|
||||||
private final ChannelFuture future;
|
private final ChannelFuture future;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user