[#1363] Make sure ChannnelConfig.setAutoRead(false) will stop read from socket directly

This commit is contained in:
Norman Maurer 2013-05-17 20:55:56 +02:00
parent 2a7bea2ad3
commit 6942dba855
2 changed files with 29 additions and 21 deletions

View File

@ -93,6 +93,11 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel {
"least one byte."); "least one byte.");
} }
} }
if (!config().isAutoRead()) {
// stop reading until next Channel.read() call
// See https://github.com/netty/netty/issues/1363
break loop;
}
} }
} }
} catch (Throwable t) { } catch (Throwable t) {

View File

@ -90,29 +90,32 @@ public abstract class AbstractOioByteChannel extends AbstractOioChannel {
break; break;
} }
if (byteBuf.isWritable()) { if (!byteBuf.isWritable()) {
continue; final int capacity = byteBuf.capacity();
} final int maxCapacity = byteBuf.maxCapacity();
if (capacity == maxCapacity) {
final int capacity = byteBuf.capacity(); if (read) {
final int maxCapacity = byteBuf.maxCapacity(); read = false;
if (capacity == maxCapacity) { pipeline.fireInboundBufferUpdated();
if (read) { if (!byteBuf.isWritable()) {
read = false; throw new IllegalStateException(
pipeline.fireInboundBufferUpdated(); "an inbound handler whose buffer is full must consume at " +
if (!byteBuf.isWritable()) { "least one byte.");
throw new IllegalStateException( }
"an inbound handler whose buffer is full must consume at " + }
"least one byte."); } else {
final int writerIndex = byteBuf.writerIndex();
if (writerIndex + available > maxCapacity) {
byteBuf.capacity(maxCapacity);
} else {
byteBuf.ensureWritable(available);
} }
} }
} else { }
final int writerIndex = byteBuf.writerIndex(); if (!config().isAutoRead()) {
if (writerIndex + available > maxCapacity) { // stop reading until next Channel.read() call
byteBuf.capacity(maxCapacity); // See https://github.com/netty/netty/issues/1363
} else { break;
byteBuf.ensureWritable(available);
}
} }
} }
} catch (Throwable t) { } catch (Throwable t) {