Use correct writerIndex when read for channel

This commit is contained in:
Norman Maurer 2014-02-16 20:21:14 +01:00
parent 9330172f80
commit 728417abd5

View File

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