From e1c47632e807fc92294f2b4a4cbbaf7629b8b215 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Sat, 21 Dec 2013 10:37:19 +0100 Subject: [PATCH] [#2079] Stop reading once the NIO byte Channel was complete drained --- .../java/io/netty/channel/nio/AbstractNioByteChannel.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java b/transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java index 4651adc457..b99343f399 100644 --- a/transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java +++ b/transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java @@ -113,6 +113,7 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel { try { do { byteBuf = allocHandle.allocate(allocator); + int writable = byteBuf.writableBytes(); int localReadAmount = doReadBytes(byteBuf); if (localReadAmount <= 0) { // not was read release the buffer @@ -123,6 +124,10 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel { pipeline.fireChannelRead(byteBuf); byteBuf = null; allocHandle.record(localReadAmount); + if (localReadAmount < writable) { + // we read less then what the buffer can hold so it seems like we drained it completely + break; + } } while (++ messages < maxMessagesPerRead); pipeline.fireChannelReadComplete();