[#1131] Codecs must not cache next buffer during processing
This commit is contained in:
parent
8d7f1e2820
commit
b1775a3223
@ -68,17 +68,17 @@ public abstract class ByteToByteDecoder extends ChannelInboundByteHandlerAdapter
|
||||
|
||||
@Override
|
||||
public void inboundBufferUpdated(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
|
||||
callDecode(ctx, in, ctx.nextInboundByteBuffer());
|
||||
callDecode(ctx, in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
ByteBuf in = ctx.inboundByteBuffer();
|
||||
ByteBuf out = ctx.nextInboundByteBuffer();
|
||||
if (!in.isReadable()) {
|
||||
callDecode(ctx, in, out);
|
||||
callDecode(ctx, in);
|
||||
}
|
||||
|
||||
ByteBuf out = ctx.nextInboundByteBuffer();
|
||||
int oldOutSize = out.readableBytes();
|
||||
try {
|
||||
decodeLast(ctx, in, out);
|
||||
@ -100,7 +100,8 @@ public abstract class ByteToByteDecoder extends ChannelInboundByteHandlerAdapter
|
||||
/**
|
||||
* Call the {@link #decode(ChannelHandlerContext, ByteBuf, ByteBuf)} method until it is done.
|
||||
*/
|
||||
private void callDecode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) {
|
||||
private void callDecode(ChannelHandlerContext ctx, ByteBuf in) {
|
||||
ByteBuf out = ctx.nextInboundByteBuffer();
|
||||
int oldOutSize = out.readableBytes();
|
||||
while (in.isReadable()) {
|
||||
int oldInSize = in.readableBytes();
|
||||
@ -116,6 +117,16 @@ public abstract class ByteToByteDecoder extends ChannelInboundByteHandlerAdapter
|
||||
if (oldInSize == in.readableBytes() || isSingleDecode()) {
|
||||
break;
|
||||
}
|
||||
|
||||
ByteBuf buf = ctx.nextInboundByteBuffer();
|
||||
if (out != buf) {
|
||||
// user changed handlers in the pipeline need to trigger fireInboundBufferUpdated maybe ?
|
||||
if (out.readableBytes() > oldOutSize) {
|
||||
ctx.fireInboundBufferUpdated();
|
||||
}
|
||||
out = ctx.nextInboundByteBuffer();
|
||||
oldOutSize = out.readableBytes();
|
||||
}
|
||||
}
|
||||
|
||||
if (out.readableBytes() > oldOutSize) {
|
||||
|
@ -54,13 +54,12 @@ public abstract class ByteToByteEncoder extends ChannelOutboundByteHandlerAdapte
|
||||
|
||||
@Override
|
||||
protected void flush(ChannelHandlerContext ctx, ByteBuf in, ChannelPromise promise) throws Exception {
|
||||
ByteBuf out = ctx.nextOutboundByteBuffer();
|
||||
boolean encoded = false;
|
||||
|
||||
while (in.isReadable()) {
|
||||
int oldInSize = in.readableBytes();
|
||||
try {
|
||||
encode(ctx, in, out);
|
||||
encode(ctx, in, ctx.nextOutboundByteBuffer());
|
||||
encoded = true;
|
||||
} catch (Throwable t) {
|
||||
Throwable cause;
|
||||
|
@ -16,7 +16,6 @@
|
||||
package io.netty.handler.codec;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.MessageBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundByteHandler;
|
||||
import io.netty.channel.ChannelInboundByteHandlerAdapter;
|
||||
@ -88,7 +87,8 @@ public abstract class ByteToMessageDecoder
|
||||
}
|
||||
|
||||
try {
|
||||
if (ctx.nextInboundMessageBuffer().unfoldAndAdd(decodeLast(ctx, in))) {
|
||||
Object msg = decodeLast(ctx, in);
|
||||
if (ctx.nextInboundMessageBuffer().unfoldAndAdd(msg)) {
|
||||
ctx.fireInboundBufferUpdated();
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
@ -106,7 +106,6 @@ public abstract class ByteToMessageDecoder
|
||||
boolean wasNull = false;
|
||||
|
||||
boolean decoded = false;
|
||||
MessageBuf<Object> out = ctx.nextInboundMessageBuffer();
|
||||
while (in.isReadable()) {
|
||||
try {
|
||||
int oldInputLength = in.readableBytes();
|
||||
@ -125,7 +124,7 @@ public abstract class ByteToMessageDecoder
|
||||
"decode() did not read anything but decoded a message.");
|
||||
}
|
||||
|
||||
if (out.unfoldAndAdd(o)) {
|
||||
if (ctx.nextInboundMessageBuffer().unfoldAndAdd(o)) {
|
||||
decoded = true;
|
||||
if (isSingleDecode()) {
|
||||
break;
|
||||
|
@ -46,7 +46,8 @@ public abstract class MessageToMessageDecoder<I> extends ChannelInboundMessageHa
|
||||
|
||||
@Override
|
||||
public final void messageReceived(ChannelHandlerContext ctx, I msg) throws Exception {
|
||||
ctx.nextInboundMessageBuffer().unfoldAndAdd(decode(ctx, msg));
|
||||
Object omsg = decode(ctx, msg);
|
||||
ctx.nextInboundMessageBuffer().unfoldAndAdd(omsg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,7 +45,8 @@ public abstract class MessageToMessageEncoder<I> extends ChannelOutboundMessageH
|
||||
@Override
|
||||
public final void flush(ChannelHandlerContext ctx, I msg) throws Exception {
|
||||
try {
|
||||
ctx.nextOutboundMessageBuffer().unfoldAndAdd(encode(ctx, msg));
|
||||
Object omsg = encode(ctx, msg);
|
||||
ctx.nextOutboundMessageBuffer().unfoldAndAdd(omsg);
|
||||
} catch (CodecException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
|
@ -16,7 +16,6 @@
|
||||
package io.netty.handler.codec;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.MessageBuf;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
@ -393,7 +392,6 @@ public abstract class ReplayingDecoder<S> extends ByteToMessageDecoder {
|
||||
boolean wasNull = false;
|
||||
|
||||
ByteBuf in = cumulation;
|
||||
MessageBuf<Object> out = ctx.nextInboundMessageBuffer();
|
||||
boolean decoded = false;
|
||||
while (in.isReadable()) {
|
||||
try {
|
||||
@ -441,7 +439,7 @@ public abstract class ReplayingDecoder<S> extends ByteToMessageDecoder {
|
||||
}
|
||||
|
||||
// A successful decode
|
||||
if (out.unfoldAndAdd(result)) {
|
||||
if (ctx.nextInboundMessageBuffer().unfoldAndAdd(result)) {
|
||||
decoded = true;
|
||||
if (isSingleDecode()) {
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user