ByteBufferCallbackAccumulator.writeTo should do buffer flipping

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2021-08-30 14:58:16 +10:00
parent b2657f1376
commit 763820e111
2 changed files with 4 additions and 4 deletions

View File

@ -66,21 +66,23 @@ public class ByteBufferCallbackAccumulator
byte[] bytes = new byte[length];
ByteBuffer buffer = BufferUtil.toBuffer(bytes);
BufferUtil.clearToFill(buffer);
BufferUtil.clear(buffer);
writeTo(buffer);
return bytes;
}
public void writeTo(ByteBuffer buffer)
{
if (buffer.remaining() < _length)
if (BufferUtil.space(buffer) < _length)
throw new IllegalArgumentException("not enough buffer space remaining");
int pos = BufferUtil.flipToFill(buffer);
for (Entry entry : _entries)
{
buffer.put(entry.buffer);
entry.callback.succeeded();
}
BufferUtil.flipToFlush(buffer, pos);
_entries.clear();
_length = 0;
}

View File

@ -85,9 +85,7 @@ public class ByteBufferMessageSink extends AbstractMessageSink
{
ByteBufferPool bufferPool = session.getByteBufferPool();
ByteBuffer buffer = bufferPool.acquire(out.getLength(), false);
BufferUtil.clearToFill(buffer);
out.writeTo(buffer);
BufferUtil.flipToFlush(buffer, 0);
try
{