Align keep-alive count tracking for HTTP
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 16 Aug 2011 12:19:49 +0000 (12:19 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 16 Aug 2011 12:19:49 +0000 (12:19 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1158227 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/coyote/http11/Http11AprProcessor.java
java/org/apache/coyote/http11/Http11NioProcessor.java
java/org/apache/coyote/http11/Http11Processor.java

index 4a94330..df0076d 100644 (file)
@@ -184,8 +184,6 @@ public class Http11AprProcessor extends AbstractHttp11Processor<Long> {
 
         long soTimeout = endpoint.getSoTimeout();
 
-        int keepAliveLeft = maxKeepAliveRequests;
-        
         boolean keptAlive = false;
         boolean openSocket = false;
         boolean sendfileInProgress = false;
@@ -253,8 +251,12 @@ public class Http11AprProcessor extends AbstractHttp11Processor<Long> {
                 }
             }
 
-            if (maxKeepAliveRequests > 0 && --keepAliveLeft == 0)
+            if (maxKeepAliveRequests == 1) {
+                keepAlive = false;
+            } else if (maxKeepAliveRequests > 0 &&
+                    socketWrapper.decrementKeepAlive() <= 0) {
                 keepAlive = false;
+            }
 
             // Process the request in the adapter
             if (!error) {
index 78f91e6..c0dd576 100644 (file)
@@ -299,10 +299,12 @@ public class Http11NioProcessor extends AbstractHttp11Processor<NioChannel> {
                 }
             }
             
-            if (maxKeepAliveRequests == 1 )
+            if (maxKeepAliveRequests == 1) {
                 keepAlive = false;
-            if (maxKeepAliveRequests > 0 && socketWrapper.decrementKeepAlive() <= 0)
+            } else if (maxKeepAliveRequests > 0 &&
+                    socketWrapper.decrementKeepAlive() <= 0) {
                 keepAlive = false;
+            }
 
             // Process the request in the adapter
             if (!error) {
index 6537788..48af529 100644 (file)
@@ -148,10 +148,6 @@ public class Http11Processor extends AbstractHttp11Processor<Socket> {
 
         int soTimeout = endpoint.getSoTimeout();
 
-        if (maxKeepAliveRequests > 0) {
-            socketWrapper.decrementKeepAlive();
-        }
-        
         int threadRatio = -1;   
         // These may return zero or negative values     
         // Only calculate a thread ratio when both are >0 to ensure we get a    
@@ -269,7 +265,10 @@ public class Http11Processor extends AbstractHttp11Processor<Socket> {
                 }
             }
 
-            if (socketWrapper.getKeepAliveLeft() == 0) {
+            if (maxKeepAliveRequests == 1) {
+                keepAlive = false;
+            } else if (maxKeepAliveRequests > 0 &&
+                    socketWrapper.decrementKeepAlive() <= 0) {
                 keepAlive = false;
             }
 
@@ -351,10 +350,6 @@ public class Http11Processor extends AbstractHttp11Processor<Socket> {
             if (isAsync() || error || inputBuffer.lastValid == 0) {
                 break;
             }
-            
-            if (maxKeepAliveRequests > 0) {
-                socketWrapper.decrementKeepAlive();
-            }
         }
 
         rp.setStage(org.apache.coyote.Constants.STAGE_ENDED);