Fix the regression caused by f31c630c8c

f31c630c8c 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()
This commit is contained in:
Trustin Lee 2014-08-15 09:41:07 -07:00
parent 2bd7a8387d
commit e3d6d8e561

View File

@ -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;
}