You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2006/08/28 13:36:13 UTC
svn commit: r437672 -
/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultIOReactor.java
Author: olegk
Date: Mon Aug 28 04:36:12 2006
New Revision: 437672
URL: http://svn.apache.org/viewvc?rev=437672&view=rev
Log:
Improved handling of cancelled keys in the default I/O reactor (second take)
Modified:
jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultIOReactor.java
Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultIOReactor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultIOReactor.java?rev=437672&r1=437671&r2=437672&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultIOReactor.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultIOReactor.java Mon Aug 28 04:36:12 2006
@@ -31,6 +31,7 @@
import java.io.IOException;
import java.net.SocketAddress;
+import java.nio.channels.CancelledKeyException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
@@ -100,13 +101,19 @@
}
}
- private void processEvents(final Set selectedKeys)
- throws IOException {
+ private void processEvents(final Set selectedKeys) throws IOException {
for (Iterator it = selectedKeys.iterator(); it.hasNext(); ) {
SelectionKey key = (SelectionKey) it.next();
+ processEvent(key);
- if (key.isValid() && key.isAcceptable()) {
+ }
+ selectedKeys.clear();
+ }
+
+ private void processEvent(final SelectionKey key) throws IOException {
+ try {
+ if (key.isAcceptable()) {
SocketChannel socketChannel = this.serverChannel.accept();
if (socketChannel != null) {
@@ -133,7 +140,7 @@
}
}
- if (key.isValid() && key.isReadable()) {
+ if (key.isReadable()) {
SessionHandle handle = (SessionHandle) key.attachment();
IOSession session = handle.getSession();
handle.resetLastRead();
@@ -141,7 +148,7 @@
this.eventDispatch.inputReady(session);
}
- if (key.isValid() && key.isWritable()) {
+ if (key.isWritable()) {
SessionHandle handle = (SessionHandle) key.attachment();
IOSession session = handle.getSession();
handle.resetLastWrite();
@@ -149,18 +156,16 @@
this.eventDispatch.outputReady(session);
}
- if (!key.isValid()) {
- SessionHandle handle = (SessionHandle) key.attachment();
- if (handle != null) {
- key.attach(null);
- IOSession session = handle.getSession();
- this.closedSessions.push(session);
- }
+ } catch (CancelledKeyException ex) {
+ SessionHandle handle = (SessionHandle) key.attachment();
+ if (handle != null) {
+ key.attach(null);
+ IOSession session = handle.getSession();
+ this.closedSessions.push(session);
}
}
- selectedKeys.clear();
}
-
+
private void processSessionTimeouts(final Set keys) {
long now = System.currentTimeMillis();
for (Iterator it = keys.iterator(); it.hasNext();) {