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 <HASH>..<HASH> 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();
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 <I>bd6e7a<I>f<I>fa<I>f1eeb<I>.

Modifications:

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

Result:

No more corruption while write single buffers.