tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r429001 - in /tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net: AprEndpoint.java JIoEndpoint.java
Date Sat, 05 Aug 2006 13:57:55 GMT
Author: remm
Date: Sat Aug  5 06:57:54 2006
New Revision: 429001

URL: http://svn.apache.org/viewvc?rev=429001&view=rev
Log:
- Fix the accept algorithm, that I had translated inaccurately in the new endpoints.

Modified:
    tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
    tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java

Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=429001&r1=429000&r2=429001&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Sat Aug  5 06:57:54
2006
@@ -1012,6 +1012,26 @@
     /**
      * Process given socket.
      */
+    protected boolean processSocketWithOptions(long socket) {
+        try {
+            if (executor == null) {
+                getWorkerThread().assignWithOptions(socket);
+            } else {
+                executor.execute(new SocketWithOptionsProcessor(socket));
+            }
+        } catch (Throwable t) {
+            // This means we got an OOM or similar creating a thread, or that
+            // the pool and its queue are full
+            log.error(sm.getString("endpoint.process.fail"), t);
+            return false;
+        }
+        return true;
+    }
+    
+
+    /**
+     * Process given socket.
+     */
     protected boolean processSocket(long socket) {
         try {
             if (executor == null) {
@@ -1080,7 +1100,7 @@
                     // Accept the next incoming connection from the server socket
                     long socket = Socket.accept(serverSock);
                     // Hand this socket off to an appropriate processor
-                    if (!setSocketOptions(socket) || !processSocket(socket)) {
+                    if (!processSocketWithOptions(socket)) {
                         // Close socket and pool right away
                         Socket.destroy(socket);
                     }
@@ -1346,6 +1366,37 @@
         protected long socket = 0;
         protected boolean event = false;
         protected boolean error = false;
+        protected boolean options = false;
+
+
+        /**
+         * Process an incoming TCP/IP connection on the specified socket.  Any
+         * exception that occurs during processing must be logged and swallowed.
+         * <b>NOTE</b>:  This method is called from our Connector's thread. 
We
+         * must assign it to our own thread so that multiple simultaneous
+         * requests can be handled.
+         *
+         * @param socket TCP socket to process
+         */
+        protected synchronized void assignWithOptions(long socket) {
+
+            // Wait for the Processor to get the previous Socket
+            while (available) {
+                try {
+                    wait();
+                } catch (InterruptedException e) {
+                }
+            }
+
+            // Store the newly available Socket and notify our thread
+            this.socket = socket;
+            event = false;
+            error = false;
+            options = true;
+            available = true;
+            notifyAll();
+
+        }
 
 
         /**
@@ -1371,6 +1422,7 @@
             this.socket = socket;
             event = false;
             error = false;
+            options = false;
             available = true;
             notifyAll();
 
@@ -1391,6 +1443,7 @@
             this.socket = socket;
             event = true;
             this.error = error;
+            options = false;
             available = true;
             notifyAll();
 
@@ -1440,7 +1493,8 @@
                     // Close socket and pool
                     Socket.destroy(socket);
                     socket = 0;
-                } else if ((!event) && (handler.process(socket) == Handler.SocketState.CLOSED))
{
+                } else if ((!event) && ((options && !setSocketOptions(socket))

+                        || handler.process(socket) == Handler.SocketState.CLOSED)) {
                     // Close socket and pool
                     Socket.destroy(socket);
                     socket = 0;
@@ -1830,6 +1884,37 @@
     }
 
 
+    // ---------------------------------------------- SocketProcessor Inner Class
+
+
+    /**
+     * This class is the equivalent of the Worker, but will simply use in an
+     * external Executor thread pool. This will also set the socket options
+     * and do the handshake.
+     */
+    protected class SocketWithOptionsProcessor implements Runnable {
+        
+        protected long socket = 0;
+        
+        public SocketWithOptionsProcessor(long socket) {
+            this.socket = socket;
+        }
+
+        public void run() {
+
+            // Process the request from this socket
+            if (!setSocketOptions(socket) 
+                    || handler.process(socket) == Handler.SocketState.CLOSED) {
+                // Close socket and pool
+                Socket.destroy(socket);
+                socket = 0;
+            }
+
+        }
+        
+    }
+    
+    
     // ---------------------------------------------- SocketProcessor Inner Class
 
 

Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java?rev=429001&r1=429000&r2=429001&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java Sat Aug  5 06:57:54
2006
@@ -309,7 +309,7 @@
                     Socket socket = serverSocketFactory.acceptSocket(serverSocket);
                     serverSocketFactory.initSocket(socket);
                     // Hand this socket off to an appropriate processor
-                    if (!setSocketOptions(socket) || !processSocket(socket)) {
+                    if (!processSocket(socket)) {
                         // Close socket right away
                         try {
                             socket.close();
@@ -348,7 +348,7 @@
         public void run() {
 
             // Process the request from this socket
-            if (!handler.process(socket)) {
+            if (!setSocketOptions(socket) || !handler.process(socket)) {
                 // Close socket
                 try {
                     socket.close();
@@ -441,7 +441,7 @@
                     continue;
 
                 // Process the request from this socket
-                if (!handler.process(socket)) {
+                if (!setSocketOptions(socket) || !handler.process(socket)) {
                     // Close socket
                     try {
                         socket.close();



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


Mime
View raw message