netty/netty — Issue #195: how to reproduce SocketTimeoutException and CancelledKeyException in NioServerSocketPipelineSink.Boss?  
Author: matthewtt
Created: 2012-02-19 09:24:24+00:00
State: open

I am not sure these two exceptions are meaningful in Boss.java. I try to reproduce them, but failed. Anyone can explain how to reproduce?
code snapshot,

public void run() {
final Thread currentThread = Thread.currentThread();

channel.shutdownLock.lock();
try {
for (;;) {
try {
if (selector.select(1000) > 0) {
selector.selectedKeys().clear();
}
channel.socket.close();
SocketChannel acceptedSocket = channel.socket.accept();
if (acceptedSocket != null) {
registerAcceptedChannel(acceptedSocket, currentThread);
}
} catch (SocketTimeoutException e) {
// Thrown every second to get ClosedChannelException
// raised.
} catch (CancelledKeyException e) {
// Raised by accept() when the server socket was closed.
} catch (ClosedSelectorException e) {
// Raised by accept() when the server socket was closed.
} catch (ClosedChannelException e) {
// Closed as requested.
break;
} catch (Throwable e) {
logger.warn(
"Failed to accept a connection.", e);
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
// Ignore
}
}
}
} finally {
channel.shutdownLock.unlock();
closeSelector();
}
}