Author: fhanik
Date: Fri Feb 23 04:58:49 2007
New Revision: 510933
URL: http://svn.apache.org/viewvc?view=rev&rev=510933
Log:
When a read or write times out, make sure the key is deregistered with the
poller
Modified:
tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioBlockingSelector.java
Modified:
tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioBlockingSelector.java
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioBlockingSelector.java?view=diff&rev=510933&r1=510932&r2=510933
==============================================================================
---
tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioBlockingSelector.java
(original)
+++
tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioBlockingSelector.java
Fri Feb 23 04:58:49 2007
@@ -41,7 +41,7 @@
* @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 @@
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 <code>selector</code> parameter is null, then it will perform a
busy read that could
@@ -149,14 +153,9 @@
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;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]