From 728417abd5a550e861a71455831fc1e884dff96d Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Sun, 16 Feb 2014 20:21:14 +0100 Subject: [PATCH] Use correct writerIndex when read for channel --- .../main/java/io/netty/channel/epoll/EpollSocketChannel.java | 5 +++-- 1 file changed, 3 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 a9af87cfdf..5ff5f8d810 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 @@ -502,10 +502,11 @@ public final class EpollSocketChannel extends AbstractEpollChannel implements So * Read bytes into the given {@link ByteBuf} and return the amount. */ private int doReadBytes(ByteBuf byteBuf) throws Exception { - ByteBuffer buf = byteBuf.internalNioBuffer(0, byteBuf.writableBytes()); + int writerIndex = byteBuf.writerIndex(); + ByteBuffer buf = byteBuf.internalNioBuffer(writerIndex, byteBuf.writableBytes()); int localReadAmount = Native.read(fd, buf, buf.position(), buf.limit()); if (localReadAmount > 0) { - byteBuf.writerIndex(byteBuf.writerIndex() + localReadAmount); + byteBuf.writerIndex(writerIndex + localReadAmount); } return localReadAmount; }