From 1db0cd60c40aba95cc7c9a0e564ea121410ccb15 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Fri, 11 May 2012 21:26:54 +0900 Subject: [PATCH] Do not attempt to flush when waiting for OP_WRITE --- .../netty/channel/socket/nio/NioSocketChannel.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java index 4b1e5c83ac..796cc467af 100644 --- a/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java @@ -161,10 +161,15 @@ public class NioSocketChannel extends AbstractNioChannel implements io.netty.cha @Override protected int doFlush() throws Exception { + final SelectionKey key = selectionKey(); + final int interestOps = key.interestOps(); + if ((interestOps & SelectionKey.OP_WRITE) != 0) { + return 0; + } + boolean open = true; boolean addOpWrite = false; boolean removeOpWrite = false; - final SocketChannel ch = javaChannel(); final int writeSpinCount = config().getWriteSpinCount(); final ChannelBuffer buf = unsafe().out().byteBuffer(); @@ -204,11 +209,9 @@ public class NioSocketChannel extends AbstractNioChannel implements io.netty.cha if (open) { if (addOpWrite) { - SelectionKey key = selectionKey(); - key.interestOps(key.interestOps() | SelectionKey.OP_WRITE); + key.interestOps(interestOps | SelectionKey.OP_WRITE); } else if (removeOpWrite) { - SelectionKey key = selectionKey(); - key.interestOps(key.interestOps() & ~SelectionKey.OP_WRITE); + key.interestOps(interestOps & ~SelectionKey.OP_WRITE); } }