Correctly handle forward of remaining data on removal
This commit is contained in:
parent
488ffb11d8
commit
768152cf88
@ -101,9 +101,13 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter
|
|||||||
@Override
|
@Override
|
||||||
public final void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
public final void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
||||||
ByteBuf buf = internalBuffer();
|
ByteBuf buf = internalBuffer();
|
||||||
|
int readable = buf.readableBytes();
|
||||||
if (buf.isReadable()) {
|
if (buf.isReadable()) {
|
||||||
ctx.fireChannelRead(buf);
|
ByteBuf bytes = buf.readBytes(readable);
|
||||||
|
buf.release();
|
||||||
|
ctx.fireChannelRead(bytes);
|
||||||
}
|
}
|
||||||
|
cumulation = null;
|
||||||
ctx.fireChannelReadComplete();
|
ctx.fireChannelReadComplete();
|
||||||
handlerRemoved0(ctx);
|
handlerRemoved0(ctx);
|
||||||
}
|
}
|
||||||
@ -123,11 +127,11 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter
|
|||||||
if (cumulation == null) {
|
if (cumulation == null) {
|
||||||
cumulation = data;
|
cumulation = data;
|
||||||
try {
|
try {
|
||||||
callDecode(ctx, data, out);
|
callDecode(ctx, cumulation, out);
|
||||||
} finally {
|
} finally {
|
||||||
if (!data.isReadable()) {
|
if (cumulation != null && !cumulation.isReadable()) {
|
||||||
|
cumulation.release();
|
||||||
cumulation = null;
|
cumulation = null;
|
||||||
data.release();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -141,12 +145,14 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter
|
|||||||
cumulation.writeBytes(data);
|
cumulation.writeBytes(data);
|
||||||
callDecode(ctx, cumulation, out);
|
callDecode(ctx, cumulation, out);
|
||||||
} finally {
|
} finally {
|
||||||
|
if (cumulation != null) {
|
||||||
if (!cumulation.isReadable()) {
|
if (!cumulation.isReadable()) {
|
||||||
cumulation.release();
|
cumulation.release();
|
||||||
cumulation = null;
|
cumulation = null;
|
||||||
} else {
|
} else {
|
||||||
cumulation.discardSomeReadBytes();
|
cumulation.discardSomeReadBytes();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
data.release();
|
data.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user