From f38991074d8da27fc793b288009d9a27a1bbe95b Mon Sep 17 00:00:00 2001 From: fhanik Date: Fri, 4 Aug 2006 21:52:51 +0000 Subject: [PATCH] Correct close down, now the close can be limited to 2 files if it needs to change git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@428896 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/coyote/http11/InternalNioInputBuffer.java | 11 +++++------ java/org/apache/tomcat/util/net/NioChannel.java | 3 ++- java/org/apache/tomcat/util/net/NioEndpoint.java | 20 ++++++++++---------- .../org/apache/tomcat/util/net/SecureNioChannel.java | 7 +++++-- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/java/org/apache/coyote/http11/InternalNioInputBuffer.java b/java/org/apache/coyote/http11/InternalNioInputBuffer.java index 247b128db..d11cb5d2c 100644 --- a/java/org/apache/coyote/http11/InternalNioInputBuffer.java +++ b/java/org/apache/coyote/http11/InternalNioInputBuffer.java @@ -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) {} } } diff --git a/java/org/apache/tomcat/util/net/NioChannel.java b/java/org/apache/tomcat/util/net/NioChannel.java index 5360ffe7f..2036c8756 100644 --- a/java/org/apache/tomcat/util/net/NioChannel.java +++ b/java/org/apache/tomcat/util/net/NioChannel.java @@ -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. diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index 38894abd1..f3eaaa570 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -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); } diff --git a/java/org/apache/tomcat/util/net/SecureNioChannel.java b/java/org/apache/tomcat/util/net/SecureNioChannel.java index 7b021d802..efdb64882 100644 --- a/java/org/apache/tomcat/util/net/SecureNioChannel.java +++ b/java/org/apache/tomcat/util/net/SecureNioChannel.java @@ -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(); + } } } -- 2.11.0