From: fhanik Date: Fri, 23 Feb 2007 12:58:49 +0000 (+0000) Subject: When a read or write times out, make sure the key is deregistered with the poller X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=9bbbdf624c7a5e6db023587b13e075a455ccf694;p=tomcat7.0 When a read or write times out, make sure the key is deregistered with the poller git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@510933 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/tomcat/util/net/NioBlockingSelector.java b/java/org/apache/tomcat/util/net/NioBlockingSelector.java index 16ee507b9..a60b0a87e 100644 --- a/java/org/apache/tomcat/util/net/NioBlockingSelector.java +++ b/java/org/apache/tomcat/util/net/NioBlockingSelector.java @@ -41,7 +41,7 @@ public class NioBlockingSelector { * @throws IOException if an IO Exception occurs in the underlying socket logic */ public static int write(ByteBuffer buf, NioChannel socket, long writeTimeout) throws IOException { - final SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector()); + SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector()); int written = 0; boolean timedout = false; int keycount = 1; //assume we can write @@ -86,18 +86,22 @@ public class NioBlockingSelector { if (timedout) throw new SocketTimeoutException(); } finally { -// if (key != null) { -// socket.getPoller().addEvent( -// new Runnable() { -// public void run() { -// key.cancel(); -// } -// }); -// } + if (timedout && key != null) { + cancelKey(socket, key); + } } return written; } + private static void cancelKey(final NioChannel socket, final SelectionKey key) { + socket.getPoller().addEvent( + new Runnable() { + public void run() { + key.cancel(); + } + }); + } + /** * Performs a blocking read using the bytebuffer for data to be read * If the selector parameter is null, then it will perform a busy read that could @@ -149,14 +153,9 @@ public class NioBlockingSelector { if (timedout) throw new SocketTimeoutException(); } finally { -// if (key != null) { -// socket.getPoller().addEvent( -// new Runnable() { -// public void run() { -// key.cancel(); -// } -// }); -// } + if (timedout && key != null) { + cancelKey(socket,key); + } } return read; }