ByteBufferCallbackAccumulator.writeTo should do buffer flipping
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
b2657f1376
commit
763820e111
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue