Skip to content

Commit

Permalink
[WEJBHTTP-45] At WildflyClientOutputStream, do not flip the pooled bu…
Browse files Browse the repository at this point in the history
…ffer at runWriteTask(), do so at the listener's invocation instead, or else you risk having it being run twice.

Also, shutdownWrites if everything is written in case pooled buffer has no remaining bytes to write (equivalent to writeFinal in the else block).
  • Loading branch information
fl4via committed Jul 8, 2020
1 parent 352e063 commit 24fa314
Showing 1 changed file with 4 additions and 3 deletions.
Expand Up @@ -66,6 +66,9 @@ public void handleEvent(StreamSinkChannel streamSinkChannel) {
}
try {
boolean closed = anyAreSet(state, FLAG_CLOSED);
if (pooledBuffer != null) {
pooledBuffer.getBuffer().flip();
}
if (closed && (pooledBuffer == null || !pooledBuffer.getBuffer().hasRemaining())) {
if (pooledBuffer != null) {
pooledBuffer.close();
Expand All @@ -76,6 +79,7 @@ public void handleEvent(StreamSinkChannel streamSinkChannel) {
state |= FLAG_DONE;
state &= ~FLAG_WRITING;
lock.notifyAll();
streamSinkChannel.shutdownWrites();
}
} else {
while (pooledBuffer.getBuffer().hasRemaining()) {
Expand Down Expand Up @@ -182,9 +186,6 @@ public void write(final byte[] b, final int off, final int len) throws IOExcepti

private void runWriteTask() {
Assert.assertHoldsLock(lock);
if (pooledBuffer != null) {
pooledBuffer.getBuffer().flip();
}
state |= FLAG_WRITING;
channel.getWriteSetter().set(channelListener);
channel.wakeupWrites();
Expand Down

0 comments on commit 24fa314

Please sign in to comment.