diff --git a/transport/src/main/java/io/netty/channel/nio/AbstractNioChannel.java b/transport/src/main/java/io/netty/channel/nio/AbstractNioChannel.java index 43b39982f6..b2852d8446 100644 --- a/transport/src/main/java/io/netty/channel/nio/AbstractNioChannel.java +++ b/transport/src/main/java/io/netty/channel/nio/AbstractNioChannel.java @@ -32,8 +32,6 @@ import java.net.SocketAddress; import java.nio.channels.CancelledKeyException; import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -49,7 +47,6 @@ public abstract class AbstractNioChannel extends AbstractChannel { protected final int readInterestOp; private volatile SelectionKey selectionKey; private volatile boolean inputShutdown; - final Queue> writableTasks = new ConcurrentLinkedQueue>(); /** * The future of the current connection attempt. If not null, subsequent diff --git a/transport/src/main/java/io/netty/channel/nio/NioEventLoop.java b/transport/src/main/java/io/netty/channel/nio/NioEventLoop.java index 78dc9876e9..dfb76dd1f6 100644 --- a/transport/src/main/java/io/netty/channel/nio/NioEventLoop.java +++ b/transport/src/main/java/io/netty/channel/nio/NioEventLoop.java @@ -194,24 +194,6 @@ public final class NioEventLoop extends SingleThreadEventLoop { } } - void executeWhenWritable(AbstractNioChannel channel, NioTask task) { - if (channel == null) { - throw new NullPointerException("channel"); - } - - if (isShutdown()) { - throw new IllegalStateException("event loop shut down"); - } - - SelectionKey key = channel.selectionKey(); - channel.writableTasks.offer(task); - - int interestOps = key.interestOps(); - if ((interestOps & SelectionKey.OP_WRITE) == 0) { - key.interestOps(interestOps | SelectionKey.OP_WRITE); - } - } - /** * Returns the percentage of the desired amount of time spent for I/O in the event loop. */ @@ -501,7 +483,8 @@ public final class NioEventLoop extends SingleThreadEventLoop { } } if ((readyOps & SelectionKey.OP_WRITE) != 0) { - processWritable(ch); + // Call forceFlush which will also take care of clear the OP_WRITE once there is nothing left to write + ch.unsafe().forceFlush(); } if ((readyOps & SelectionKey.OP_CONNECT) != 0) { // remove OP_CONNECT as otherwise Selector.select(..) will always return without blocking @@ -513,37 +496,10 @@ public final class NioEventLoop extends SingleThreadEventLoop { unsafe.finishConnect(); } } catch (CancelledKeyException e) { - if (readyOps != -1 && (readyOps & SelectionKey.OP_WRITE) != 0) { - unregisterWritableTasks(ch); - } unsafe.close(unsafe.voidPromise()); } } - private static void processWritable(AbstractNioChannel ch) { - NioTask task; - for (;;) { - task = ch.writableTasks.poll(); - if (task == null) { break; } - processSelectedKey(ch.selectionKey(), task); - } - - // Call forceFlush which will also take care of clear the OP_WRITE once there is nothing left to write - ch.unsafe().forceFlush(); - } - - private static void unregisterWritableTasks(AbstractNioChannel ch) { - NioTask task; - for (;;) { - task = ch.writableTasks.poll(); - if (task == null) { - break; - } else { - invokeChannelUnregistered(task, ch.selectionKey(), null); - } - } - } - private static void processSelectedKey(SelectionKey k, NioTask task) { int state = 0; try { @@ -585,7 +541,6 @@ public final class NioEventLoop extends SingleThreadEventLoop { } for (AbstractNioChannel ch: channels) { - unregisterWritableTasks(ch); ch.unsafe().close(ch.unsafe().voidPromise()); } }