Created
July 22, 2014 15:08
-
-
Save rhs/d541ae1dbe1aee89dd5d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* this method will change the readerIndex on bytes to the latest read position | |
*/ | |
public void pump(ByteBuf bytes) | |
{ | |
if (bytes.readableBytes() < 8) | |
{ | |
return; | |
} | |
try | |
{ | |
synchronized (lock) | |
{ | |
while (bytes.readableBytes() > 0) | |
{ | |
int capacity = transport.capacity(); | |
if (capacity > 0) { | |
ByteBuffer tail = transport.tail(); | |
int min = Math.min(capacity, bytes.readableBytes()); | |
tail.limit(min); | |
bytes.readBytes(tail); | |
transport.process(); | |
checkSASL(); | |
dispatch(); | |
} else { | |
if (capacity == 0) { | |
System.out.println("abandoning: " + bytes.readableBytes()); | |
} else { | |
System.out.println("transport closed, discarding: " + bytes.readableBytes()); | |
} | |
bytes.skipBytes(bytes.readableBytes()); | |
} | |
} | |
} | |
} | |
finally | |
{ | |
// After everything is processed we still need to check for more dispatches! | |
dispatch(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment