ffang commented on code in PR #3674:
URL: https://github.com/apache/cxf/pull/3674#discussion_r4460753774


##########
rt/transports/http-hc5/src/main/java/org/apache/cxf/transport/http/asyncclient/hc5/SharedInputBuffer.java:
##########
@@ -97,6 +97,9 @@ public int consumeContent(final ByteBuffer buffer, boolean 
last) throws IOExcept
             }
 
             if (!buffer().hasRemaining() && !this.endOfStream) {
+                // Wake up a reader waiting for data first: only the reader 
signals suspendInput,
+                // once it has drained the buffer
+                this.condition.signalAll();

Review Comment:
   Thanks @reta, good point, the second one isn't needed. The signal before 
waiting is what wakes up the reader. When the buffer is full, the dispatcher 
waits on `suspendInput`, and the reader only signals that after it has drained 
the buffer and is about to wait for data again. Nothing is added to the buffer 
after the wait, so the signal after the `if` only woke up the reader for 
nothing: it found no data and waited again. When the buffer isn't full, or at 
the end of the stream, there's no wait, so a single signal is enough there as 
well.
   
   In d294c14eac I moved the signal before the `if` and removed the one after 
it, so it's signalled once:
   
   ```java
   // Wake up a reader waiting for data before waiting for the buffer to be 
drained: only
   // the reader signals suspendInput, once it has drained the buffer
   this.condition.signalAll();
   
   if (!buffer().hasRemaining() && !this.endOfStream) {
       try {
           suspendInput.await();
       } catch (InterruptedException ex) {
           throw new IOException("Interrupted while waiting buffer to be 
drained ");
       }
   }
   ```
   
   Best Regards
   Freeman



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to