Correct close down, now the close can be limited to 2 files if it needs to change
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 4 Aug 2006 21:52:51 +0000 (21:52 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 4 Aug 2006 21:52:51 +0000 (21:52 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@428896 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/coyote/http11/InternalNioInputBuffer.java
java/org/apache/tomcat/util/net/NioChannel.java
java/org/apache/tomcat/util/net/NioEndpoint.java
java/org/apache/tomcat/util/net/SecureNioChannel.java

index 247b128..d11cb5d 100644 (file)
@@ -588,13 +588,12 @@ public class InternalNioInputBuffer implements InputBuffer {
                     if (key != null) key.interestOps(SelectionKey.OP_READ);
                 } catch (CancelledKeyException ckx) {
                     try {
-                        if ( key != null && key.attachment() != null ) {
-                            KeyAttachment ka = (KeyAttachment)key.attachment();
-                            ka.setError(true); //set to collect this socket immediately
+                        if ( att != null ) {
+                            att.setError(true); //set to collect this socket immediately
+                            att.setWakeUp(false);
                         }
-                        socket.getIOChannel().socket().close();
-                        socket.close();
-                        att.setWakeUp(false);
+                        try {socket.close();}catch (Exception ignore){}
+                        if ( socket.isOpen() ) socket.close(true);
                     } catch (Exception ignore) {}
                 }
             }
index 5360ffe..2036c87 100644 (file)
@@ -51,11 +51,12 @@ public class NioChannel implements ByteChannel{
      * @todo Implement this java.nio.channels.Channel method
      */
     public void close() throws IOException {
+        getIOChannel().socket().close();
         sc.close();
     }
 
     public void close(boolean force) throws IOException {
-        close();
+        if (isOpen() || force ) close();
     }
     /**
      * Tells whether or not this channel is open.
index 38894ab..f3eaaa5 100644 (file)
@@ -937,8 +937,8 @@ public class NioEndpoint {
                                 KeyAttachment ka = (KeyAttachment)key.attachment();
                                 ka.setError(true); //set to collect this socket immediately
                             }
-                            socket.getIOChannel().socket().close();
-                            socket.close();
+                            try {socket.close();}catch (Exception ignore){}
+                            if ( socket.isOpen() ) socket.close(true);
                         } catch ( Exception ignore ) {}
                     }
                 }
@@ -1259,16 +1259,16 @@ public class NioEndpoint {
                     if ((event) && (handler.event(socket, error) == Handler.SocketState.CLOSED)) {
                         // Close socket and pool
                         try {
-                            socket.getIOChannel().socket().close();
-                            socket.close();
+                            try {socket.close();}catch (Exception ignore){}
+                            if ( socket.isOpen() ) socket.close(true);
                         }catch ( Exception x ) {
                             log.error("",x);
                         }
                     } else if ((!event) && (handler.process(socket) == Handler.SocketState.CLOSED)) {
                         // Close socket and pool
                         try {
-                            socket.getIOChannel().socket().close();
-                            socket.close();
+                            try {socket.close();}catch (Exception ignore){}
+                            if ( socket.isOpen() ) socket.close(true);
                         }catch ( Exception x ) {
                             log.error("",x);
                         }
@@ -1431,8 +1431,8 @@ public class NioEndpoint {
             if (handler.process(socket) == Handler.SocketState.CLOSED) {
                 // Close socket and pool
                 try {
-                    socket.getIOChannel().socket().close();
-                    socket.close();
+                    try {socket.close();}catch (Exception ignore){}
+                    if ( socket.isOpen() ) socket.close(true);
                 } catch ( Exception x ) {
                     log.error("",x);
                 }
@@ -1467,8 +1467,8 @@ public class NioEndpoint {
             if (handler.event(socket, error) == Handler.SocketState.CLOSED) {
                 // Close socket and pool
                 try {
-                    socket.getIOChannel().socket().close();
-                    socket.close();
+                    try {socket.close();}catch (Exception ignore){}
+                    if ( socket.isOpen() ) socket.close(true);
                 } catch ( Exception x ) {
                     log.error("",x);
                 }
index 7b021d8..efdb648 100644 (file)
@@ -268,8 +268,11 @@ public class SecureNioChannel extends NioChannel  {
         try {
             close();
         }finally {
-            closed = true;
-            sc.close();
+            if ( force || closed ) {
+                closed = true;
+                sc.socket().close();
+                sc.close();
+            }
         }
     }