Bring the Http11 protocol implementations closer together.
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 8 Jul 2011 14:04:08 +0000 (14:04 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 8 Jul 2011 14:04:08 +0000 (14:04 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1144317 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/coyote/http11/AbstractHttp11Processor.java
java/org/apache/coyote/http11/Http11AprProcessor.java
java/org/apache/coyote/http11/Http11AprProtocol.java
java/org/apache/coyote/http11/Http11NioProcessor.java
java/org/apache/coyote/http11/Http11NioProtocol.java
java/org/apache/coyote/http11/Http11Processor.java
java/org/apache/coyote/http11/Http11Protocol.java
java/org/apache/coyote/http11/LocalStrings.properties

index 5e56b56..e3e489c 100644 (file)
@@ -104,6 +104,12 @@ public abstract class AbstractHttp11Processor extends AbstractProcessor {
 
 
     /**
+     * Comet used.
+     */
+    protected boolean comet = false;
+
+
+    /**
      * Regular expression that defines the restricted user agents.
      */
     protected Pattern restrictedUserAgents = null;
@@ -1242,6 +1248,9 @@ public abstract class AbstractHttp11Processor extends AbstractProcessor {
     }
 
 
+    public abstract SocketState event(SocketStatus status) throws IOException;
+
+
     /**
      * Provides a mechanism for those connector implementations (currently only
      * NIO) that need to reset timeouts from Async timeouts to standard HTTP
index dd0a880..38fb8e9 100644 (file)
@@ -94,12 +94,6 @@ public class Http11AprProcessor extends AbstractHttp11Processor {
 
 
     /**
-     * Comet used.
-     */
-    protected boolean comet = false;
-
-
-    /**
      * Socket associated with the current connection.
      */
     protected SocketWrapper<Long> socket = null;
@@ -128,6 +122,7 @@ public class Http11AprProcessor extends AbstractHttp11Processor {
      *
      * @throws IOException error during an I/O operation
      */
+    @Override
     public SocketState event(SocketStatus status)
         throws IOException {
         
index 5c7de18..c228f8f 100644 (file)
@@ -214,8 +214,7 @@ public class Http11AprProtocol extends AbstractHttp11Protocol {
         @Override
         public SocketState process(SocketWrapper<Long> socket,
                 SocketStatus status) {
-            Http11AprProcessor processor =
-                connections.remove(socket.getSocket());
+            Http11AprProcessor processor = connections.remove(socket.getSocket());
             
             socket.setAsync(false);
 
@@ -227,6 +226,8 @@ public class Http11AprProtocol extends AbstractHttp11Protocol {
                     processor = createProcessor();
                 }
 
+                initSsl(socket, processor);
+
                 SocketState state = SocketState.CLOSED;
                 do {
                     if (processor.isAsync() || state == SocketState.ASYNC_END) {
@@ -266,7 +267,6 @@ public class Http11AprProtocol extends AbstractHttp11Protocol {
                     recycledProcessors.offer(processor);
                 }
                 return state;
-
             } catch (java.net.SocketException e) {
                 // SocketExceptions are normal
                 log.debug(sm.getString(
@@ -292,6 +292,11 @@ public class Http11AprProtocol extends AbstractHttp11Protocol {
             return SocketState.CLOSED;
         }
 
+        private void initSsl(SocketWrapper<Long> socket,
+                Http11AprProcessor processor) {
+            // NOOP for APR
+        }
+
         protected Http11AprProcessor createProcessor() {
             Http11AprProcessor processor = new Http11AprProcessor(
                     proto.getMaxHttpHeaderSize(), (AprEndpoint)proto.endpoint,
index 4f30570..fcc6b75 100644 (file)
@@ -96,11 +96,6 @@ public class Http11NioProcessor extends AbstractHttp11Processor {
     protected NioEndpoint.SendfileData sendfileData = null;
 
     /**
-     * Comet used.
-     */
-    protected boolean comet = false;
-    
-    /**
      * Closed flag, a Comet async thread can 
      * signal for this Nio processor to be closed and recycled instead
      * of waiting for a timeout.
@@ -123,6 +118,7 @@ public class Http11NioProcessor extends AbstractHttp11Processor {
      *
      * @throws IOException error during an I/O operation
      */
+    @Override
     public SocketState event(SocketStatus status)
         throws IOException {
 
index ff5d677..e4dc0df 100644 (file)
@@ -245,16 +245,7 @@ public class Http11NioProtocol extends AbstractHttp11JsseProtocol {
                     processor = createProcessor();
                 }
 
-                if (proto.isSSLEnabled() &&
-                        (proto.sslImplementation != null)
-                        && (socket.getSocket() instanceof SecureNioChannel)) {
-                    SecureNioChannel ch = (SecureNioChannel)socket.getSocket();
-                    processor.setSslSupport(
-                            proto.sslImplementation.getSSLSupport(
-                                    ch.getSslEngine().getSession()));
-                } else {
-                    processor.setSslSupport(null);
-                }
+                initSsl(socket, processor);
 
                 SocketState state = SocketState.CLOSED;
                 do {
@@ -299,7 +290,6 @@ public class Http11NioProtocol extends AbstractHttp11JsseProtocol {
                     release(socket, processor);
                 }
                 return state;
-
             } catch (java.net.SocketException e) {
                 // SocketExceptions are normal
                 log.debug(sm.getString(
@@ -323,6 +313,21 @@ public class Http11NioProtocol extends AbstractHttp11JsseProtocol {
             return SocketState.CLOSED;
         }
 
+        private void initSsl(SocketWrapper<NioChannel> socket,
+                Http11NioProcessor processor) {
+            if (proto.isSSLEnabled() &&
+                    (proto.sslImplementation != null)
+                    && (socket.getSocket() instanceof SecureNioChannel)) {
+                SecureNioChannel ch = (SecureNioChannel)socket.getSocket();
+                processor.setSslSupport(
+                        proto.sslImplementation.getSSLSupport(
+                                ch.getSslEngine().getSession()));
+            } else {
+                processor.setSslSupport(null);
+            }
+
+        }
+
         public Http11NioProcessor createProcessor() {
             Http11NioProcessor processor = new Http11NioProcessor(
                     proto.getMaxHttpHeaderSize(), (NioEndpoint)proto.endpoint,
index 5cc1e18..633f02c 100644 (file)
@@ -386,6 +386,13 @@ public class Http11Processor extends AbstractHttp11Processor {
     }
 
 
+    @Override
+    public SocketState event(SocketStatus status) throws IOException {
+        // Should never reach this code but in case we do...
+        throw new IOException(
+                sm.getString("http11processor.comet.notsupported"));
+    }
+
     // ----------------------------------------------------- ActionHook Methods
 
 
index 2a6fd92..341e12d 100644 (file)
@@ -136,8 +136,12 @@ public class Http11Protocol extends AbstractHttp11JsseProtocol {
         }
 
         @Override
-        public SocketState process(SocketWrapper<Socket> socket, SocketStatus status) {
+        public SocketState process(SocketWrapper<Socket> socket,
+                SocketStatus status) {
             Http11Processor processor = connections.remove(socket);
+
+            socket.setAsync(false); //no longer check for timeout
+
             try {
                 if (processor == null) {
                     processor = recycledProcessors.poll();
@@ -146,18 +150,14 @@ public class Http11Protocol extends AbstractHttp11JsseProtocol {
                     processor = createProcessor();
                 }
 
-                if (proto.isSSLEnabled() && (proto.sslImplementation != null)) {
-                    processor.setSSLSupport(
-                            proto.sslImplementation.getSSLSupport(
-                                    socket.getSocket()));
-                } else {
-                    processor.setSSLSupport(null);
-                }
+                initSsl(socket,processor);
                 
                 SocketState state = SocketState.CLOSED;
                 do {
                     if (processor.isAsync() || state == SocketState.ASYNC_END) {
                         state = processor.asyncDispatch(status);
+                    } else if (processor.comet) {
+                        state = processor.event(status);
                     } else {
                         state = processor.process(socket);
                     }
@@ -166,12 +166,18 @@ public class Http11Protocol extends AbstractHttp11JsseProtocol {
                         state = processor.asyncPostProcess();
                     }
                 } while (state == SocketState.ASYNC_END);
-                // TODO Better to add a new state to the AsyncStateMachine and
-                //      remove ASYNC_END entirely
 
                 if (state == SocketState.LONG) {
+                    // In the middle of processing a request/response. Keep the
+                    // socket associated with the processor.
                     connections.put(socket, processor);
+                } else if (state == SocketState.OPEN){
+                    // In keep-alive but between requests. OK to recycle
+                    // processor. Continue to poll for the next request.
+                    processor.recycle();
+                    recycledProcessors.offer(processor);
                 } else {
+                    // Connection closed. OK to recycle the processor.
                     processor.recycle();
                     recycledProcessors.offer(processor);
                 }
@@ -200,6 +206,18 @@ public class Http11Protocol extends AbstractHttp11JsseProtocol {
             return SocketState.CLOSED;
         }
         
+        private void initSsl(SocketWrapper<Socket> socket,
+                Http11Processor processor) {
+            if (proto.isSSLEnabled() && (proto.sslImplementation != null)) {
+                processor.setSSLSupport(
+                        proto.sslImplementation.getSSLSupport(
+                                socket.getSocket()));
+            } else {
+                processor.setSSLSupport(null);
+            }
+
+        }
+
         protected Http11Processor createProcessor() {
             Http11Processor processor = new Http11Processor(
                     proto.getMaxHttpHeaderSize(), (JIoEndpoint)proto.endpoint,
index b45140e..dd49940 100644 (file)
@@ -34,6 +34,7 @@ http11processor.socket.info=Exception getting socket information
 http11processor.socket.ssl=Exception getting SSL attributes
 http11processor.socket.sslreneg=Exception re-negotiating SSL connection
 http11processor.socket.timeout=Error setting socket timeout
+http11processor.comet.notsupported=The Comet protocol is not supported by this connector
 
 iib.eof.error=Unexpected EOF read on the socket
 iib.requestheadertoolarge.error=Request header is too large