Skip to content

Instantly share code, notes, and snippets.

@normanmaurer
Created June 26, 2014 13:37
Show Gist options
  • Select an option

  • Save normanmaurer/25cea8247baf82ea5ab2 to your computer and use it in GitHub Desktop.

Select an option

Save normanmaurer/25cea8247baf82ea5ab2 to your computer and use it in GitHub Desktop.
public int pump(ByteBuf bytes)
{
int bytesRead = 0;
try
{
if (bytes.readableBytes() < 8)
{
return 0;
}
synchronized (lock)
{
final ByteBuffer input = transport.getInputBuffer();
if (bytes.readableBytes() > input.remaining())
{
for (;;)
{
int remaining = input.remaining();
if (remaining == 0)
{
System.err.println("Buffer full!!!");
break;
}
int min = Math.min(remaining, bytes.readableBytes());
ByteBuffer tmp = bytes.internalNioBuffer(bytes.readerIndex() + bytesRead, min);
input.put(tmp);
if (!processBuffer())
{
System.err.println("DEBUG This.. Process Buffer returned false!!!!!!!!!!!!!");
bytesRead += min;
break;
}
bytesRead += min;
}
}
else
{
ByteBuffer tmp = bytes.internalNioBuffer(bytes.readerIndex(), bytes.readableBytes());
bytesRead = tmp.remaining();
input.put(tmp);
if (!processBuffer()) return 0;
}
return bytesRead;
}
}
finally
{
dispatch();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment