ReplayingDecoder: keep explicit track of cleanup state.

This fixes a bug introduced by 1f3d35bd whereby cleanup() won't get
run if the cumulation buffer was emptied.  This is important for
codecs like HTTP: In particular, empty 200 OK responses without a
Content-Length header would fail to decode.
This commit is contained in:
marius a. eriksen 2011-12-07 09:15:44 -08:00
parent 5cb865c4ce
commit 49c797fb3e

View File

@ -17,6 +17,7 @@ package org.jboss.netty.handler.codec.replay;
import java.net.SocketAddress;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicBoolean;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBufferFactory;
@ -295,6 +296,8 @@ public abstract class ReplayingDecoder<T extends Enum<T>>
private final AtomicReference<ChannelBuffer> cumulation =
new AtomicReference<ChannelBuffer>();
private final AtomicBoolean needsCleanup =
new AtomicBoolean(false);
private final boolean unfold;
private ReplayingDecoderBuffer replayable;
private T state;
@ -436,6 +439,7 @@ public abstract class ReplayingDecoder<T extends Enum<T>>
}
ChannelBuffer cumulation = cumulation(ctx);
needsCleanup.set(true);
cumulation.discardReadBytes();
cumulation.writeBytes(input);
callDecode(ctx, e.getChannel(), cumulation, e.getRemoteAddress());
@ -532,14 +536,14 @@ public abstract class ReplayingDecoder<T extends Enum<T>>
private void cleanup(ChannelHandlerContext ctx, ChannelStateEvent e)
throws Exception {
try {
ChannelBuffer cumulation = this.cumulation.getAndSet(null);
if (cumulation == null) {
if (!needsCleanup.getAndSet(false)) {
return;
}
ChannelBuffer cumulation = this.cumulation.getAndSet(null);
replayable.terminate();
if (cumulation.readable()) {
if (cumulation != null && cumulation.readable()) {
// Make sure all data was read before notifying a closed channel.
callDecode(ctx, e.getChannel(), cumulation, null);
}