Make keptAlive initialization common between the connectors
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 6 Sep 2011 11:26:30 +0000 (11:26 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 6 Sep 2011 11:26:30 +0000 (11:26 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1165608 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/coyote/http11/AbstractHttp11Processor.java
java/org/apache/coyote/http11/Http11AprProcessor.java
java/org/apache/coyote/http11/Http11NioProcessor.java
java/org/apache/coyote/http11/Http11Processor.java
java/org/apache/tomcat/util/net/AbstractEndpoint.java
java/org/apache/tomcat/util/net/AprEndpoint.java
java/org/apache/tomcat/util/net/JIoEndpoint.java
java/org/apache/tomcat/util/net/NioEndpoint.java

index 63c84ee..c364a17 100644 (file)
@@ -87,6 +87,16 @@ public abstract class AbstractHttp11Processor<S> extends AbstractProcessor<S> {
 
 
     /**
+     * Flag used to indicate that the socket should treat the next request
+     * processed like a keep-alive connection - i.e. one where there may not be
+     * any data to process. The initial value of this flag on entering the
+     * process method is different for connectors that use polling (NIO / APR -
+     * data is always expected) compared to those that use blocking (BIO - data
+     * is only expected if the connection isn't in the keep-alive state).
+     */
+    protected boolean keptAlive;
+
+    /**
      * Flag that indicates that send file processing is in progress and that the
      * socket should not be returned to the poller (where a poller is used).
      */
index 1e28147..b481fcc 100644 (file)
@@ -184,6 +184,11 @@ public class Http11AprProcessor extends AbstractHttp11Processor<Long> {
         openSocket = false;
         sendfileInProgress = false;
         readComplete = true;
+        if (endpoint.getUsePolling()) {
+            keptAlive = false;
+        } else {
+            keptAlive = socketWrapper.isKeptAlive();
+        }
 
         int soTimeout = endpoint.getSoTimeout();
 
@@ -191,8 +196,6 @@ public class Http11AprProcessor extends AbstractHttp11Processor<Long> {
             socketWrapper.setKeepAliveLeft(0);
         }
 
-        boolean keptAlive = false;
-
         long socketRef = socketWrapper.getSocket().longValue();
 
         while (!error && keepAlive && !comet && !isAsync() &&
index 74d3016..87ebfd4 100644 (file)
@@ -213,6 +213,11 @@ public class Http11NioProcessor extends AbstractHttp11Processor<NioChannel> {
         openSocket = false;
         sendfileInProgress = false;
         readComplete = true;
+        if (endpoint.getUsePolling()) {
+            keptAlive = false;
+        } else {
+            keptAlive = socketWrapper.isKeptAlive();
+        }
         
         int soTimeout = endpoint.getSoTimeout();
 
@@ -220,8 +225,6 @@ public class Http11NioProcessor extends AbstractHttp11Processor<NioChannel> {
             socketWrapper.setKeepAliveLeft(0);
         }
 
-        boolean keptAlive = false;
-        
         while (!error && keepAlive && !comet && !isAsync() &&
                 !endpoint.isPaused()) {
 
index 55c7eff..fbf99b7 100644 (file)
@@ -148,6 +148,11 @@ public class Http11Processor extends AbstractHttp11Processor<Socket> {
         openSocket = false;
         sendfileInProgress = false;
         readComplete = true;
+        if (endpoint.getUsePolling()) {
+            keptAlive = false;
+        } else {
+            keptAlive = socketWrapper.isKeptAlive();
+        }
 
         int soTimeout = endpoint.getSoTimeout();
 
@@ -155,8 +160,6 @@ public class Http11Processor extends AbstractHttp11Processor<Socket> {
             socketWrapper.setKeepAliveLeft(0);
         }
 
-        boolean keptAlive = socketWrapper.isKeptAlive();
-
         while (!error && keepAlive && !comet && !isAsync() &&
                 !endpoint.isPaused()) {
 
index f606817..54aad90 100644 (file)
@@ -559,9 +559,12 @@ public abstract class AbstractEndpoint {
 
     protected abstract Log getLog();
     // Flags to indicate optional feature support
+    // Some of these are always hard-coded, some are hard-coded to false (i.e.
+    // the endpoint does not support them) and some are configurable.
     public abstract boolean getUseSendfile();
     public abstract boolean getUseComet();
     public abstract boolean getUseCometTimeout();
+    public abstract boolean getUsePolling();
     
     protected LimitLatch initializeConnectionLatch() {
         if (connectionLimitLatch==null) {
index d0b2ee2..e5dc675 100644 (file)
@@ -160,6 +160,8 @@ public class AprEndpoint extends AbstractEndpoint {
     public boolean getUseComet() { return useComet; }
     @Override
     public boolean getUseCometTimeout() { return false; } // Not supported
+    @Override
+    public boolean getUsePolling() { return true; } // Always supported
 
 
     /**
index 3ef6a0c..fc3bbef 100644 (file)
@@ -108,6 +108,8 @@ public class JIoEndpoint extends AbstractEndpoint {
     public boolean getUseCometTimeout() { return false; } // Not supported
     @Override
     public boolean getDeferAccept() { return false; } // Not supported
+    @Override
+    public boolean getUsePolling() { return false; } // Not supported
 
 
     // ------------------------------------------------ Handler Inner Interface
index cb628df..558cf55 100644 (file)
@@ -332,6 +332,8 @@ public class NioEndpoint extends AbstractEndpoint {
     public boolean getUseComet() { return useComet; }
     @Override
     public boolean getUseCometTimeout() { return getUseComet(); }
+    @Override
+    public boolean getUsePolling() { return true; } // Always supported
 
 
     /**