[#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.");
}
}
if (!config().isAutoRead()) {
// stop reading until next Channel.read() call
// See https://github.com/netty/netty/issues/1363
break loop;
}
}
}
} catch (Throwable t) {

View File

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