You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2007/02/16 18:36:21 UTC

svn commit: r508510 - /jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java

Author: olegk
Date: Fri Feb 16 09:36:19 2007
New Revision: 508510

URL: http://svn.apache.org/viewvc?view=rev&rev=508510
Log:
Added extra sync point to ensure the connection is ready to transmit an HTTP response

Modified:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java?view=diff&rev=508510&r1=508509&r2=508510
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java Fri Feb 16 09:36:19 2007
@@ -487,6 +487,28 @@
             final ServerConnState connState,
             final ContentIOControl ioControl) throws IOException, HttpException {
 
+        // Make sure the connection is ready for output
+        // (the previous worker thread terminated)
+        synchronized (connState) {
+            try {
+                for (;;) {
+                    int currentState = connState.getOutputState();
+                    if (currentState == ServerConnState.READY) {
+                        break;
+                    }
+                    if (currentState == ServerConnState.SHUTDOWN) {
+                        break;
+                    }
+                    connState.wait();
+                }
+            } catch (InterruptedException ex) {
+                connState.shutdown();
+            }
+            if (connState.getOutputState() == ServerConnState.SHUTDOWN) {
+                return;
+            }
+        }
+        
         // Response is ready to be committed
         HttpResponse response = connState.getResponse();
         
@@ -512,7 +534,10 @@
             try {
                 for (;;) {
                     int currentState = connState.getOutputState();
-                    if (currentState == expectedSate || currentState == ServerConnState.SHUTDOWN) {
+                    if (currentState == expectedSate) {
+                        break;
+                    }
+                    if (currentState == ServerConnState.SHUTDOWN) {
                         break;
                     }
                     connState.wait();