Refactored output control in the async HTTP/1.1 protocol handlers
authorOleg Kalnichevski <olegk@apache.org>
Mon, 19 Nov 2018 09:28:51 +0000 (10:28 +0100)
committerOleg Kalnichevski <olegk@apache.org>
Tue, 20 Nov 2018 07:37:03 +0000 (08:37 +0100)
httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java

index 1ee2333..5b549ba 100644 (file)
@@ -374,20 +374,18 @@ abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends HttpMessage,
             outputLock.unlock();
         }
         if (connState.compareTo(ConnectionState.SHUTDOWN) < 0) {
-            if (isOutputReady()) {
-                produceOutput();
-            } else {
-                final int pendingOutputRequests = outputRequests.get();
-                outputLock.lock();
-                try {
-                    if (!outbuf.hasData() && outputRequests.compareAndSet(pendingOutputRequests, 0)) {
-                        ioSession.clearEvent(SelectionKey.OP_WRITE);
-                    } else {
-                        outputRequests.addAndGet(-pendingOutputRequests);
-                    }
-                } finally {
-                    outputLock.unlock();
+            produceOutput();
+            final int pendingOutputRequests = outputRequests.get();
+            final boolean outputPending = isOutputReady();
+            outputLock.lock();
+            try {
+                if (!outputPending && !outbuf.hasData() && outputRequests.compareAndSet(pendingOutputRequests, 0)) {
+                    ioSession.clearEvent(SelectionKey.OP_WRITE);
+                } else {
+                    outputRequests.addAndGet(-pendingOutputRequests);
                 }
+            } finally {
+                outputLock.unlock();
             }
 
             outputLock.lock();