From d5b7c131dd4de9a1a28e0791746680503fc29907 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Fri, 25 Jul 2014 17:27:22 +0200 Subject: [PATCH] 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 88bd6e7a9300073707f305409fa6481f1eeb2077. Modifications: Correctly use the writerIndex as argument when call Native.writeAddress(...) Result: No more corruption while write single buffers. --- .../main/java/io/netty/channel/epoll/EpollSocketChannel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannel.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannel.java index 9f8973bbaf..1d2f824259 100644 --- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannel.java +++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannel.java @@ -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();