tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1231740 - in /tomcat/trunk/java/org/apache/tomcat/util/net: AprEndpoint.java JIoEndpoint.java NioEndpoint.java
Date Sun, 15 Jan 2012 20:04:06 GMT
Author: markt
Date: Sun Jan 15 20:04:05 2012
New Revision: 1231740

URL: http://svn.apache.org/viewvc?rev=1231740&view=rev
Log:
Ensure that connections from unlockAccept() do not get passed to a
processor.
Reduce differences between BIO, NIO and APR acceptor code.

Modified:
    tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
    tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java
    tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=1231740&r1=1231739&r2=1231740&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Sun Jan 15 20:04:05 2012
@@ -941,21 +941,16 @@ public class AprEndpoint extends Abstrac
         return log;
     }
 
-    // --------------------------------------------------- Acceptor Inner Class
-
 
+    // --------------------------------------------------- Acceptor Inner Class
     /**
-     * Server socket acceptor thread.
+     * The background thread that listens for incoming TCP/IP connections and
+     * hands them off to an appropriate processor.
      */
     protected class Acceptor extends AbstractEndpoint.Acceptor {
 
         private final Log log = LogFactory.getLog(AprEndpoint.Acceptor.class);
 
-
-        /**
-         * The background thread that listens for incoming TCP/IP connections and
-         * hands them off to an appropriate processor.
-         */
         @Override
         public void run() {
 
@@ -997,17 +992,13 @@ public class AprEndpoint extends Abstrac
                     // Successful accept, reset the error delay
                     errorDelay = 0;
 
-                    /*
-                     * In the case of a deferred accept unlockAccept needs to
-                     * send data. This data will be rubbish, so destroy the
-                     * socket and don't process it.
-                     */
-                    if (deferAccept && (paused || !running)) {
-                        destroySocket(socket);
-                        continue;
-                    }
-                    // Hand this socket off to an appropriate processor
-                    if (!processSocketWithOptions(socket)) {
+                    if (running && !paused) {
+                        // Hand this socket off to an appropriate processor
+                        if (!processSocketWithOptions(socket)) {
+                            // Close socket and pool right away
+                            destroySocket(socket);
+                        }
+                    } else {
                         // Close socket and pool right away
                         destroySocket(socket);
                     }

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java?rev=1231740&r1=1231739&r2=1231740&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java Sun Jan 15 20:04:05 2012
@@ -177,14 +177,11 @@ public class JIoEndpoint extends Abstrac
 
     // --------------------------------------------------- Acceptor Inner Class
     /**
-     * Server socket acceptor thread.
+     * The background thread that listens for incoming TCP/IP connections and
+     * hands them off to an appropriate processor.
      */
     protected class Acceptor extends AbstractEndpoint.Acceptor {
 
-        /**
-         * The background thread that listens for incoming TCP/IP connections and
-         * hands them off to an appropriate processor.
-         */
         @Override
         public void run() {
 
@@ -227,23 +224,15 @@ public class JIoEndpoint extends Abstrac
                     errorDelay = 0;
 
                     // Configure the socket
-                    if (setSocketOptions(socket)) {
+                    if (running && !paused && setSocketOptions(socket)) {
                         // Hand this socket off to an appropriate processor
                         if (!processSocket(socket)) {
                             // Close socket right away
-                            try {
-                                socket.close();
-                            } catch (IOException e) {
-                                // Ignore
-                            }
+                            closeSocket(socket);
                         }
                     } else {
                         // Close socket right away
-                        try {
-                            socket.close();
-                        } catch (IOException e) {
-                            // Ignore
-                        }
+                        closeSocket(socket);
                     }
                 } catch (IOException x) {
                     if (running) {
@@ -257,13 +246,21 @@ public class JIoEndpoint extends Abstrac
                     ExceptionUtils.handleThrowable(t);
                     log.error(sm.getString("endpoint.accept.fail"), t);
                 }
-                // The processor will recycle itself when it finishes
             }
             state = AcceptorState.ENDED;
         }
     }
 
 
+    private void closeSocket(Socket socket) {
+        try {
+            socket.close();
+        } catch (IOException e) {
+            // Ignore
+        }
+    }
+
+
     // ------------------------------------------- SocketProcessor Inner Class
 
 

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1231740&r1=1231739&r2=1231740&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Sun Jan 15 20:04:05 2012
@@ -742,17 +742,14 @@ public class NioEndpoint extends Abstrac
         return log;
     }
 
-    // --------------------------------------------------- Acceptor Inner Class
-
 
+    // --------------------------------------------------- Acceptor Inner Class
     /**
-     * Server socket acceptor thread.
+     * The background thread that listens for incoming TCP/IP connections and
+     * hands them off to an appropriate processor.
      */
     protected class Acceptor extends AbstractEndpoint.Acceptor {
-        /**
-         * The background thread that listens for incoming TCP/IP connections and
-         * hands them off to an appropriate processor.
-         */
+
         @Override
         public void run() {
 
@@ -794,24 +791,17 @@ public class NioEndpoint extends Abstrac
                     // Successful accept, reset the error delay
                     errorDelay = 0;
 
-                    // Hand this socket off to an appropriate processor
-                    //TODO FIXME - this is currently a blocking call, meaning we will be
blocking
-                    //further accepts until there is a thread available.
-                    if ( running && (!paused) && socket != null ) {
-                        // setSocketOptions() will add channel to the poller
-                        // if successful
+                    // setSocketOptions() will add channel to the poller
+                    // if successful
+                    if (running && !paused) {
                         if (!setSocketOptions(socket)) {
-                            try {
-                                socket.socket().close();
-                                socket.close();
-                            } catch (IOException ix) {
-                                if (log.isDebugEnabled())
-                                    log.debug("", ix);
-                            }
+                            closeSocket(socket);
                         }
+                    } else {
+                        closeSocket(socket);
                     }
                 } catch (SocketTimeoutException sx) {
-                    //normal condition
+                    // Ignore: Normal condition
                 } catch (IOException x) {
                     if (running) {
                         log.error(sm.getString("endpoint.accept.fail"), x);
@@ -837,9 +827,27 @@ public class NioEndpoint extends Abstrac
                     ExceptionUtils.handleThrowable(t);
                     log.error(sm.getString("endpoint.accept.fail"), t);
                 }
-            }//while
+            }
             state = AcceptorState.ENDED;
-        }//run
+        }
+    }
+
+
+    private void closeSocket(SocketChannel socket) {
+        try {
+            socket.socket().close();
+        } catch (IOException ioe)  {
+            if (log.isDebugEnabled()) {
+                log.debug("", ioe);
+            }
+        }
+        try {
+            socket.close();
+        } catch (IOException ioe) {
+            if (log.isDebugEnabled()) {
+                log.debug("", ioe);
+            }
+        }
     }
 
 



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


Mime
View raw message