more work towards making the JIO connector ready for async
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 8 Mar 2010 16:38:35 +0000 (16:38 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 8 Mar 2010 16:38:35 +0000 (16:38 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@920392 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/coyote/http11/Http11Processor.java
java/org/apache/tomcat/util/net/JIoEndpoint.java
java/org/apache/tomcat/util/net/SocketWrapper.java

index e74d3f9..2d3ef33 100644 (file)
@@ -185,12 +185,13 @@ public class Http11Processor extends AbstractHttp11Processor implements ActionHo
             error = true;
         }
 
-        boolean keptAlive = false;
+        boolean keptAlive = socketWrapper.isKeptAlive();
 
         while (started && !error && keepAlive) {
 
             // Parsing the request header
             try {
+                //TODO - calculate timeout based on length in queue (System.currentTimeMills() - wrapper.getLastAccess() is the time in queue)
                 if (keptAlive) {
                     if (keepAliveTimeout > 0) {
                         socket.setSoTimeout(keepAliveTimeout);
index c42c9b2..270dd39 100644 (file)
@@ -187,10 +187,12 @@ public class JIoEndpoint extends AbstractEndpoint {
         public void run() {
                boolean close = false;
             // Process the request from this socket
-            if (!setSocketOptions(socket.getSocket())) { //this does a handshake and resets socket value
+            if ( (!socket.isKeptAlive()) && (!setSocketOptions(socket.getSocket())) ) { //this does a handshake and resets socket value
                close = true;
-            } else if (!handler.process(socket)) {
-                close = true;
+            }
+            
+            if ( (!close) ) {
+                close = !handler.process(socket);
             }
             if (close) {
                // Close socket
@@ -203,7 +205,10 @@ public class JIoEndpoint extends AbstractEndpoint {
                     // Ignore
                 }
             } else {
+                socket.setKeptAlive(true);
+                socket.access();
                 //keepalive connection
+                //TODO - servlet3 check async status, we may just be in a hold pattern
                 getExecutor().execute(new SocketProcessor(socket));
             }
             // Finish up this request
index 6247019..21b79ae 100644 (file)
@@ -21,13 +21,14 @@ public class SocketWrapper<E> {
     
     protected volatile E socket;
     
-    protected long lastAccess = -1;
-    protected boolean currentAccess = false;
+    protected volatile long lastAccess = -1;
+    protected volatile boolean currentAccess = false;
     protected long timeout = -1;
     protected boolean error = false;
     protected long lastRegistered = 0;
     protected volatile int keepAliveLeft = 100;
     protected boolean async = false;
+    protected boolean keptAlive = false;
     
     public SocketWrapper(E socket) {
         reset(socket);
@@ -55,5 +56,6 @@ public class SocketWrapper<E> {
     public int getKeepAliveLeft() { return this.keepAliveLeft; }
     public void setKeepAliveLeft(int keepAliveLeft) { this.keepAliveLeft = keepAliveLeft;}
     public int decrementKeepAlive() { return (--keepAliveLeft);}
-
+    public boolean isKeptAlive() {return keptAlive;}
+    public void setKeptAlive(boolean keptAlive) {this.keptAlive = keptAlive;}
 }