Skip to content

Instantly share code, notes, and snippets.

@rhs
Created July 22, 2014 15:08
Show Gist options
  • Save rhs/d541ae1dbe1aee89dd5d to your computer and use it in GitHub Desktop.
Save rhs/d541ae1dbe1aee89dd5d to your computer and use it in GitHub Desktop.
/**
* 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