Catch the cancelled key exceptions and act appropriately
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 22 Jun 2006 19:59:39 +0000 (19:59 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 22 Jun 2006 19:59:39 +0000 (19:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@416456 13f79535-47bb-0310-9956-ffa450edef68

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

index 486a99a..3959f1a 100644 (file)
@@ -32,6 +32,7 @@ import java.nio.channels.Selector;
 import java.nio.channels.SelectionKey;\r
 import org.apache.tomcat.util.net.NioEndpoint.KeyAttachment;\r
 import org.apache.tomcat.util.net.NioEndpoint.Poller;\r
+import java.nio.channels.CancelledKeyException;\r
 \r
 /**\r
  * Implementation of InputBuffer which provides HTTP request header parsing as\r
@@ -564,13 +565,21 @@ public class InternalNioInputBuffer implements InputBuffer {
             if ( !timedOut && nRead == 0 ) \r
                 try {\r
                     final SelectionKey key = socket.keyFor(poller.getSelector());\r
-                    KeyAttachment att = (KeyAttachment)key.attachment();\r
+                    final KeyAttachment att = (KeyAttachment)key.attachment();\r
                     att.setWakeUp(true);\r
                     \r
                     poller.addEvent(\r
                         new Runnable() {\r
                             public void run() {\r
-                                if ( key != null ) key.interestOps(SelectionKey.OP_READ);\r
+                                try {\r
+                                    if (key != null) key.interestOps(SelectionKey.OP_READ);\r
+                                } catch (CancelledKeyException ckx) {\r
+                                    try {\r
+                                        socket.socket().close();\r
+                                        socket.close();\r
+                                        att.setWakeUp(false);\r
+                                    } catch (Exception ignore) {}\r
+                                }\r
                             }\r
                     });\r
                     synchronized (att.getMutex()) { att.getMutex().wait(25);}\r
index 14c9414..9665922 100644 (file)
@@ -1106,7 +1106,14 @@ public class NioEndpoint {
             if ( att != null ) att.setWakeUp(false);\r
             Runnable r = new Runnable() {\r
                 public void run() {\r
-                    if ( key != null ) key.interestOps(SelectionKey.OP_READ);\r
+                    try {\r
+                        if (key != null) key.interestOps(SelectionKey.OP_READ);\r
+                    }catch ( CancelledKeyException ckx ) {\r
+                        try {\r
+                            socket.socket().close();\r
+                            socket.close();\r
+                        } catch ( Exception ignore ) {}\r
+                    }\r
                 }\r
             };\r
             addEvent(r);\r