tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1144317 - /tomcat/trunk/java/org/apache/coyote/http11/
Date Fri, 08 Jul 2011 14:04:09 GMT
Author: markt
Date: Fri Jul  8 14:04:08 2011
New Revision: 1144317

URL: http://svn.apache.org/viewvc?rev=1144317&view=rev
Log:
Bring the Http11 protocol implementations closer together.

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

Modified: tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java?rev=1144317&r1=1144316&r2=1144317&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java Fri Jul  8 14:04:08
2011
@@ -104,6 +104,12 @@ public abstract class AbstractHttp11Proc
 
 
     /**
+     * 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 AbstractHttp11Proc
     }
 
 
+    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

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java?rev=1144317&r1=1144316&r2=1144317&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java Fri Jul  8 14:04:08
2011
@@ -94,12 +94,6 @@ public class Http11AprProcessor extends 
 
 
     /**
-     * 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 
      *
      * @throws IOException error during an I/O operation
      */
+    @Override
     public SocketState event(SocketStatus status)
         throws IOException {
         

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java?rev=1144317&r1=1144316&r2=1144317&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java Fri Jul  8 14:04:08
2011
@@ -214,8 +214,7 @@ public class Http11AprProtocol extends A
         @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 A
                     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 A
                     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 A
             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,

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java?rev=1144317&r1=1144316&r2=1144317&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java Fri Jul  8 14:04:08
2011
@@ -96,11 +96,6 @@ public class Http11NioProcessor extends 
     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 
      *
      * @throws IOException error during an I/O operation
      */
+    @Override
     public SocketState event(SocketStatus status)
         throws IOException {
 

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java?rev=1144317&r1=1144316&r2=1144317&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java Fri Jul  8 14:04:08
2011
@@ -245,16 +245,7 @@ public class Http11NioProtocol extends A
                     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 A
                     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 A
             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,

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java?rev=1144317&r1=1144316&r2=1144317&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java Fri Jul  8 14:04:08 2011
@@ -386,6 +386,13 @@ public class Http11Processor extends Abs
     }
 
 
+    @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
 
 

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11Protocol.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11Protocol.java?rev=1144317&r1=1144316&r2=1144317&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11Protocol.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11Protocol.java Fri Jul  8 14:04:08 2011
@@ -136,8 +136,12 @@ public class Http11Protocol extends Abst
         }
 
         @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 Abst
                     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 Abst
                         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 Abst
             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,

Modified: tomcat/trunk/java/org/apache/coyote/http11/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/LocalStrings.properties?rev=1144317&r1=1144316&r2=1144317&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/LocalStrings.properties Fri Jul  8 14:04:08
2011
@@ -34,6 +34,7 @@ http11processor.socket.info=Exception ge
 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



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message