From 23d15c71ee0173d4d762b8520c12a3d0907540a8 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Fri, 15 Aug 2014 09:41:07 -0700 Subject: [PATCH] Fix the regression caused by f31c630c8cc15c4de1cc7e45b6c5c8053d5bcb75 f31c630c8cc15c4de1cc7e45b6c5c8053d5bcb75 was causing SocketGatheringWriteTest to fail because it does not take the case where an empty buffer exists in a gathering write. When there is an empty buffer in a gathering write, the number of buffers returned by ChannelOutboundBuffer.nioBuffer() and the actual number of write attemps can differ. To remove the write requests correctly, a byte transport must use ChannelOutboundBuffer.removeBytes() --- .../channel/socket/nio/NioSocketChannel.java | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 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 99a43e4556..1798c512c1 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 @@ -296,22 +296,11 @@ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty break; } - if (done) { - // Release all written buffers. - // - // It's important to loop only over nioBufferCnt as there may be other messages in the - // ChannelOutboundBuffer that are not of type ByteBuf and so was not included for gathering-write. - // - // See https://github.com/netty/netty/issues/2769 - for (int i = nioBufferCnt; i > 0; i --) { - final ByteBuf buf = (ByteBuf) in.current(); - in.progress(buf.readableBytes()); - in.remove(); - } - } else { + // Release the fully written buffers, and update the indexes of the partially written buffer. + in.removeBytes(writtenBytes); + + if (!done) { // Did not write all buffers completely. - // Release the fully written buffers and update the indexes of the partially written buffer. - in.removeBytes(writtenBytes); incompleteWrite(setOpWrite); break; }