From e3d6d8e56163b5d2c30e1dbb05e38a68c21597bc 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 44058669f2..0c54e2f0fe 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 @@ -297,22 +297,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; }