int preReadInputBBPos = byteBuffer.position();
Selector readSelector = null;
SelectionKey tmpKey = null;
try {
ReadableByteChannel readableChannel = (ReadableByteChannel) channel;
while(count > 0) {
count = readableChannel.read(byteBuffer);
if(count > -1) {
byteRead += count;
} else {
byteRead = count;
}
}
if(byteRead == 0 && byteBuffer.position() == preReadInputBBPos) {
readSelector = selectorFactory.getSelector();
if(readSelector == null) {
return 0;
}
count = 1;
tmpKey = channel.register(readSelector, SelectionKey.OP_READ);
tmpKey.interestOps(tmpKey.interestOps() | SelectionKey.OP_READ);
int code = readSelector.select(readTimeout);
tmpKey.interestOps(tmpKey.interestOps() & (~SelectionKey.OP_READ));
if(code == 0) {
return 0; // Return on the main Selector and try again.
}
while(count > 0) {
count = readableChannel.read(byteBuffer);
if(count > -1) {
byteRead += count;
} else {
byteRead = count;
}