Issue #6566 - cleanups of ByteBufferCallbackAccumulator

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2021-08-27 11:49:18 +10:00
parent 83f2265653
commit 1dce9df48d
3 changed files with 8 additions and 12 deletions

View File

@ -15,7 +15,6 @@ package org.eclipse.jetty.io;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.BufferUtil;
@ -74,19 +73,16 @@ public class ByteBufferCallbackAccumulator
public void writeTo(ByteBuffer buffer) public void writeTo(ByteBuffer buffer)
{ {
for (Iterator<Entry> iterator = _entries.iterator(); iterator.hasNext();) if (BufferUtil.space(buffer) < _length)
throw new IllegalArgumentException("not enough buffer space remaining");
for (Entry entry : _entries)
{ {
Entry entry = iterator.next();
_length -= entry.buffer.remaining();
buffer.put(entry.buffer); buffer.put(entry.buffer);
iterator.remove();
entry.callback.succeeded(); entry.callback.succeeded();
} }
_entries.clear();
if (!_entries.isEmpty()) _length = 0;
throw new IllegalStateException("remaining entries: " + _entries.size());
if (_length != 0)
throw new IllegalStateException("non-zero length: " + _length);
} }
public void fail(Throwable t) public void fail(Throwable t)

View File

@ -156,8 +156,8 @@ public abstract class DispatchedMessageSink extends AbstractMessageSink
@Override @Override
public void succeeded() public void succeeded()
{ {
session.demand(1);
super.succeeded(); super.succeeded();
session.demand(1);
} }
}; };
} }

View File

@ -326,7 +326,7 @@ public class JettyWebSocketFrameHandler implements FrameHandler
if (activeMessageSink == null) if (activeMessageSink == null)
{ {
callback.succeeded(); callback.succeeded();
coreSession.demand(1); demand();
return; return;
} }