Skip to content

Instantly share code, notes, and snippets.

@rhs
Created July 18, 2014 13:53
Show Gist options
  • Save rhs/3215bad3bfe402199978 to your computer and use it in GitHub Desktop.
Save rhs/3215bad3bfe402199978 to your computer and use it in GitHub Desktop.
public void pump(ByteBuf bytes)
{
if (bytes.readableBytes() < 8)
{
return;
}
try
{
synchronized (lock)
{
while (bytes.readerIndex() < bytes.writerIndex())
{
int capacity = transport.capacity();
if (capacity > 0) {
final ByteBuffer tail = transport.tail();
int min = Math.min(capacity, bytes.readableBytes());
ByteBuffer tmp = bytes.internalNioBuffer(bytes.readerIndex(), min);
tail.put(tmp);
transport.process();
checkSASL();
dispatch();
bytes.readerIndex(bytes.readerIndex() + min);
}
}
}
}
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