Accept all ready connections after select the keys. See #257

This commit is contained in:
norman 2012-04-12 09:27:34 +02:00
parent 2c2d64a75e
commit 4c449e902f

View File

@ -216,14 +216,26 @@ class NioServerSocketPipelineSink extends AbstractNioChannelSink {
try {
for (;;) {
try {
if (selector.select(1000) > 0) {
selector.selectedKeys().clear();
if (selector.select(1000) <= 0) {
// just continue if there was nothing selected
continue;
}
SocketChannel acceptedSocket = channel.socket.accept();
if (acceptedSocket != null) {
// There was something selected if we reach this point, so clear
// the selected keys
selector.selectedKeys().clear();
// accept connections in a for loop until no new connection is ready
for (;;) {
SocketChannel acceptedSocket = channel.socket.accept();
if (acceptedSocket == null) {
break;
}
registerAcceptedChannel(acceptedSocket, currentThread);
}
} catch (SocketTimeoutException e) {
// Thrown every second to get ClosedChannelException
// raised.