Fixed issue: NETTY-164 ReplayingDecoderBuffer.readableBytes() and capacity() should not return Integer.MAX_VALUE if the connection is closed.

* Added ReplayingDecoderBuffer.terminate(), which makes readableBytes() and capacity() to return an ordinary value instead of Integer.MAX_VALUE
This commit is contained in:
Trustin Lee 2009-06-03 08:58:06 +00:00
parent 2100462235
commit 3acda248c1
2 changed files with 16 additions and 2 deletions

View File

@ -455,6 +455,7 @@ public abstract class ReplayingDecoder<T extends Enum<T>>
private void cleanup(ChannelHandlerContext ctx, ChannelStateEvent e)
throws Exception {
ChannelBuffer cumulation = cumulation(ctx);
replayable.terminate();
try {
if (cumulation.readable()) {
// Make sure all data was read before notifying a closed channel.

View File

@ -46,13 +46,22 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
private static final Error REPLAY = new ReplayError();
private final ChannelBuffer buffer;
private boolean terminated;
ReplayingDecoderBuffer(ChannelBuffer buffer) {
this.buffer = buffer;
}
void terminate() {
terminated = true;
}
public int capacity() {
return Integer.MAX_VALUE;
if (terminated) {
return buffer.capacity();
} else {
return Integer.MAX_VALUE;
}
}
public void clear() {
@ -210,7 +219,11 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
}
public int readableBytes() {
return Integer.MAX_VALUE - buffer.readerIndex();
if (terminated) {
return buffer.readableBytes();
} else {
return Integer.MAX_VALUE - buffer.readerIndex();
}
}
public byte readByte() {