Author: remm
Date: Mon Jul 20 16:28:28 2015
New Revision: 1691974

URL: http://svn.apache.org/r1691974
Log:
Remove confusing closeSocket method.
Remove nested exception catch, doesn't seem very useful.
58103: Add some sync to avoid double close.

Modified:
    tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java?rev=1691974&r1=1691973&r2=1691974&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java Mon Jul 20 
16:28:28 2015
@@ -430,26 +430,30 @@ public class Nio2Endpoint extends Abstra
         }
         try {
             handler.release(socket);
-            try {
-                if (socket.getSocket() != null) {
-                    socket.getSocket().close(true);
-                }
-            } catch (Exception e){
-                if (log.isDebugEnabled()) {
-                    log.debug(sm.getString(
-                            "endpoint.debug.socketCloseFail"), e);
+        } catch (Throwable e) {
+            ExceptionUtils.handleThrowable(e);
+            if (log.isDebugEnabled()) log.error("",e);
+        }
+        try {
+            if (socket.getSocket() != null) {
+                synchronized (socket.getSocket()) {
+                    if (socket.getSocket() != null && 
socket.getSocket().isOpen()) {
+                        countDownConnection();
+                        socket.getSocket().close(true);
+                    }
                 }
             }
+        } catch (Throwable e) {
+            ExceptionUtils.handleThrowable(e);
+            if (log.isDebugEnabled()) log.error("",e);
+        }
+        try {
             Nio2SocketWrapper nio2Socket = (Nio2SocketWrapper) socket;
-            try {
-                if (nio2Socket.getSendfileData() != null
-                        && nio2Socket.getSendfileData().fchannel != null
-                        && nio2Socket.getSendfileData().fchannel.isOpen()) {
-                    nio2Socket.getSendfileData().fchannel.close();
-                }
-            } catch (Exception ignore) {
+            if (nio2Socket.getSendfileData() != null
+                    && nio2Socket.getSendfileData().fchannel != null
+                    && nio2Socket.getSendfileData().fchannel.isOpen()) {
+                nio2Socket.getSendfileData().fchannel.close();
             }
-            countDownConnection();
         } catch (Throwable e) {
             ExceptionUtils.handleThrowable(e);
             if (log.isDebugEnabled()) log.error("",e);
@@ -523,12 +527,24 @@ public class Nio2Endpoint extends Abstra
                         // Hand this socket off to an appropriate processor
                         if (!setSocketOptions(socket)) {
                             countDownConnection();
-                            closeSocket(socket);
-                        }
+                            try {
+                                socket.close();
+                            } catch (IOException ioe) {
+                                if (log.isDebugEnabled()) {
+                                    log.debug("", ioe);
+                                }
+                            }
+                       }
                     } else {
                         countDownConnection();
                         // Close socket right away
-                        closeSocket(socket);
+                        try {
+                            socket.close();
+                        } catch (IOException ioe) {
+                            if (log.isDebugEnabled()) {
+                                log.debug("", ioe);
+                            }
+                        }
                     }
                 } catch (Throwable t) {
                     ExceptionUtils.handleThrowable(t);
@@ -541,17 +557,6 @@ public class Nio2Endpoint extends Abstra
     }
 
 
-    private void closeSocket(AsynchronousSocketChannel socket) {
-        try {
-            socket.close();
-        } catch (IOException ioe) {
-            if (log.isDebugEnabled()) {
-                log.debug("", ioe);
-            }
-        }
-    }
-
-
     public static class Nio2SocketWrapper extends 
SocketWrapperBase<Nio2Channel> {
 
         private static final ThreadLocal<AtomicInteger> 
nestedWriteCompletionCount =



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

Reply via email to