tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael <freew...@adsl-209-204-165-151.sonic.net>
Subject [PATCH] PoolTcpEndpoint.java (was: Thread priority)
Date Thu, 19 Dec 2002 08:53:26 GMT
Now that you've attracted my attention to this file....
I couldn't figure what the point of this code was:

            if (running) {
                if(null!= serverSocket) {
                     if(factory==null){
                        accepted = serverSocket.accept();
                    }
                    else {
                        accepted = factory.acceptSocket(serverSocket);
                    }
--->                if(!running) {
--->                    if(null != accepted) {
--->                        accepted.close();  // rude, but unlikely!
--->                        accepted = null;
--->                    }
--->                }
                    if( factory != null && accepted != null)
                        factory.initSocket( accepted );
                }
            }

since it could never be executed, until I realized that you must have 
meant this:

Index: PoolTcpEndpoint.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/net/PoolTcpEndpoint.java,v
retrieving revision 1.9
diff -u -r1.9 PoolTcpEndpoint.java
--- PoolTcpEndpoint.java        19 Dec 2002 05:31:46 -0000      1.9
+++ PoolTcpEndpoint.java        19 Dec 2002 08:20:21 -0000
@@ -120,7 +120,7 @@
     private ServerSocket serverSocket;
 
     ThreadPoolRunnable listener;
-    private boolean running = false;
+    private volatile boolean running = false;
     private boolean initialized = false;
     static final int debug=0;
 
While you're in there, some clean-up would be nice, too:

@@ -338,27 +338,21 @@
     // -------------------- Private methods
 
     Socket acceptSocket() {
+       if (!running || serverSocket == null)  return null;
+
         Socket accepted = null;
 
        try {
-           if (running) {
-               if(null!= serverSocket) {
-                     if(factory==null){
-                       accepted = serverSocket.accept();
-                   }
-                   else {
-                       accepted = factory.acceptSocket(serverSocket);
-                   }
-                   if(!running) {
-                       if(null != accepted) {
+           accepted = (factory == null) ?
+               serverSocket.accept() :
+               factory.acceptSocket( serverSocket );
+
+           if (!running && accepted != null) {
                            accepted.close();  // rude, but unlikely!
                            accepted = null;
-                       }
-                   }
+           }
                    if( factory != null && accepted != null)
                        factory.initSocket( accepted );
-               }
-           }
        }
        catch(InterruptedIOException iioe) {
            // normal part -- should happen regularly so



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


Mime
View raw message