[#2079] Stop reading once the NIO byte Channel was complete drained

This commit is contained in:
Norman Maurer 2013-12-21 10:37:19 +01:00
parent 6ac54cd791
commit e1c47632e8

View File

@ -113,6 +113,7 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel {
try { try {
do { do {
byteBuf = allocHandle.allocate(allocator); byteBuf = allocHandle.allocate(allocator);
int writable = byteBuf.writableBytes();
int localReadAmount = doReadBytes(byteBuf); int localReadAmount = doReadBytes(byteBuf);
if (localReadAmount <= 0) { if (localReadAmount <= 0) {
// not was read release the buffer // not was read release the buffer
@ -123,6 +124,10 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel {
pipeline.fireChannelRead(byteBuf); pipeline.fireChannelRead(byteBuf);
byteBuf = null; byteBuf = null;
allocHandle.record(localReadAmount); 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); } while (++ messages < maxMessagesPerRead);
pipeline.fireChannelReadComplete(); pipeline.fireChannelReadComplete();