proper handling of cancelled keys

This commit is contained in:
Trustin Lee 2009-03-04 13:04:28 +00:00
parent 4d95e233bc
commit cd3859b002

View File

@ -27,6 +27,7 @@ import static org.jboss.netty.channel.Channels.*;
import java.io.IOException;
import java.net.SocketAddress;
import java.nio.channels.AsynchronousCloseException;
import java.nio.channels.CancelledKeyException;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.NotYetConnectedException;
import java.nio.channels.ScatteringByteChannel;
@ -244,23 +245,15 @@ class NioWorker implements Runnable {
for (Iterator<SelectionKey> i = selectedKeys.iterator(); i.hasNext();) {
SelectionKey k = i.next();
i.remove();
if (!k.isValid()) {
try {
if (k.isReadable()) {
read(k);
}
if (k.isWritable()) {
write(k);
}
} catch (CancelledKeyException e) {
close(k);
continue;
}
if (k.isReadable()) {
read(k);
}
if (!k.isValid()) {
close(k);
continue;
}
if (k.isWritable()) {
write(k);
}
}
}