From f17e56b33bfb725474015e19cdddc5d1254ea989 Mon Sep 17 00:00:00 2001 From: norman Date: Tue, 10 Apr 2012 11:18:34 +0200 Subject: [PATCH] Accept all ready sockets for the SelectionKey. See #240 --- .../channel/socket/nio/AbstractNioWorker.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioWorker.java b/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioWorker.java index c65b6ff451..1db5154b27 100644 --- a/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioWorker.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioWorker.java @@ -464,17 +464,22 @@ abstract class AbstractNioWorker implements Worker { protected boolean accept(SelectionKey key) { NioServerSocketChannel channel = (NioServerSocketChannel) key.attachment(); try { - SocketChannel acceptedSocket = channel.socket.accept(); - if (acceptedSocket != null) { - + boolean handled = false; + + // accept all sockets that are waiting atm + for (;;) { + SocketChannel acceptedSocket = channel.socket.accept(); + if (acceptedSocket == null) { + break; + } // TODO: Remove the casting stuff ChannelPipeline pipeline = channel.getConfig().getPipelineFactory().getPipeline(); registerTask(NioAcceptedSocketChannel.create(channel.getFactory(), pipeline, channel, channel.getPipeline().getSink(), acceptedSocket, (NioWorker) this), null); - return true; + handled = true; } - return false; + return handled; } catch (SocketTimeoutException e) { // Thrown every second to get ClosedChannelException // raised.