Correctly write single ByteBuf with memoryAddress

Motivation:

While optimize gathering writes I introduced a bug when writing single ByteBuf that have a memoryAddress. This regression was introduced by 88bd6e7a93.

Modifications:

Correctly use the writerIndex as argument when call Native.writeAddress(...)

Result:

No more corruption while write single buffers.
This commit is contained in:
Norman Maurer 2014-07-25 17:27:22 +02:00
parent 88bd6e7a93
commit d5b7c131dd

View File

@ -116,8 +116,9 @@ public final class EpollSocketChannel extends AbstractEpollChannel implements So
if (buf.hasMemoryAddress()) {
long memoryAddress = buf.memoryAddress();
int readerIndex = buf.readerIndex();
int writerIndex = buf.writerIndex();
for (;;) {
int localFlushedAmount = Native.writeAddress(fd, memoryAddress, readerIndex, readableBytes);
int localFlushedAmount = Native.writeAddress(fd, memoryAddress, readerIndex, writerIndex);
if (localFlushedAmount > 0) {
writtenBytes += localFlushedAmount;
if (writtenBytes == readableBytes) {
@ -125,7 +126,6 @@ public final class EpollSocketChannel extends AbstractEpollChannel implements So
break;
}
readerIndex += localFlushedAmount;
readableBytes -= localFlushedAmount;
} else {
// Returned EAGAIN need to set EPOLLOUT
setEpollOut();