Handle CancelledKeyException. See #327

This commit is contained in:
Norman Maurer 2012-08-31 12:44:17 +02:00
parent fee1492c6b
commit e2464a14a4

View File

@ -273,11 +273,15 @@ abstract class AbstractNioWorker implements Worker {
// loop over all keys as the selector may was unblocked because of a closed channel
for (SelectionKey key: selector.keys()) {
SelectableChannel ch = key.channel();
if ((ch instanceof DatagramChannel && !((DatagramChannel) ch).isConnected()) ||
ch instanceof SocketChannel && !((SocketChannel) ch).isConnected()) {
notConnected = true;
// cancel the key just to be on the safe side
key.cancel();
try {
if ((ch instanceof DatagramChannel && !((DatagramChannel) ch).isConnected()) ||
ch instanceof SocketChannel && !((SocketChannel) ch).isConnected()) {
notConnected = true;
// cancel the key just to be on the safe side
key.cancel();
}
} catch (CancelledKeyException e) {
// ignore
}
}
if (notConnected) {