Skip to content

Commit

Permalink
Fix #6562 last written bytebuffer (#6563) (#6579)
Browse files Browse the repository at this point in the history
Fixes #6562 the last written bytebuffer calculation.
Also fixed an associated issue with unnecessary flush of an empty when last calculation already signalled last.
  • Loading branch information
gregw committed Aug 4, 2021
1 parent 266d8f0 commit b0140da
Show file tree
Hide file tree
Showing 2 changed files with 199 additions and 11 deletions.
Expand Up @@ -847,10 +847,12 @@ public void write(byte[] b, int off, int len) throws IOException
// Blocking write
try
{
boolean complete = false;
// flush any content from the aggregate
if (BufferUtil.hasContent(_aggregate))
{
channelWrite(_aggregate, last && len == 0);
complete = last && len == 0;
channelWrite(_aggregate, complete);

// should we fill aggregate again from the buffer?
if (len > 0 && !last && len <= _commitSize && len <= maximizeAggregateSpace())
Expand Down Expand Up @@ -880,7 +882,7 @@ public void write(byte[] b, int off, int len) throws IOException
}
channelWrite(view, last);
}
else if (last)
else if (last && !complete)
{
channelWrite(BufferUtil.EMPTY_BUFFER, true);
}
Expand All @@ -907,7 +909,7 @@ public void write(ByteBuffer buffer) throws IOException
{
checkWritable();
long written = _written + len;
last = _channel.getResponse().isAllContentWritten(_written);
last = _channel.getResponse().isAllContentWritten(written);
flush = last || len > 0 || BufferUtil.hasContent(_aggregate);

if (last && _state == State.OPEN)
Expand Down Expand Up @@ -951,13 +953,17 @@ public void write(ByteBuffer buffer) throws IOException
{
// Blocking write
// flush any content from the aggregate
boolean complete = false;
if (BufferUtil.hasContent(_aggregate))
channelWrite(_aggregate, last && len == 0);
{
complete = last && len == 0;
channelWrite(_aggregate, complete);
}

// write any remaining content in the buffer directly
if (len > 0)
channelWrite(buffer, last);
else if (last)
else if (last && !complete)
channelWrite(BufferUtil.EMPTY_BUFFER, true);

onWriteComplete(last, null);
Expand Down

0 comments on commit b0140da

Please sign in to comment.