Skip to content

Instantly share code, notes, and snippets.

@normanmaurer
Created June 18, 2014 13:50
Show Gist options
  • Select an option

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

Select an option

Save normanmaurer/a7876420db026cc7d040 to your computer and use it in GitHub Desktop.
ByteBuf buffer = PooledByteBufAllocator.DEFAULT.heapBuffer(1024 * 1024);
try
{
synchronized (connection.getTrio().getLock())
{
int count;
//todo an optimisation here would be to only use the buffer if we need more that one recv
while ((count = receiver.recv(buffer.array(), buffer.arrayOffset() + buffer.writerIndex(), buffer.writableBytes())> 0)
{
// Increment the writer index by the number of bytes written into it while calling recv.
buffer.writerIndex(buffer.writerIndex() + count);
}
// we keep reading until we get end of messages, i.e. -1
if (count == 0)
{
// todo this is obviously incorrect, investigate return;
}
sessionSPI.serverSend(address, delivery.getMessageFormat(), buffer.nioBuffer());
receiver.advance();
receiver.flow(1);
delivery.settle();
}
}
finally
{
buffer.release();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment