Make sure the cumulation Buffer is only created if really needed. See
#88
This commit is contained in:
parent
55e7a85160
commit
0d5c7d3d2e
@ -205,17 +205,28 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
ChannelBuffer cumulation = cumulation(ctx);
|
||||
if (cumulation.readable()) {
|
||||
cumulation.discardReadBytes();
|
||||
cumulation.writeBytes(input);
|
||||
callDecode(ctx, e.getChannel(), cumulation, e.getRemoteAddress());
|
||||
} else {
|
||||
if (cumulation == null) {
|
||||
// the cumulation buffer is not created yet so just pass the input to callDecode(...) method
|
||||
callDecode(ctx, e.getChannel(), input, e.getRemoteAddress());
|
||||
if (input.readable()) {
|
||||
// seems like there is something readable left in the input buffer. So create the cumulation buffer and copy the input into it
|
||||
ChannelBuffer cumulation = cumulation(ctx);
|
||||
cumulation.writeBytes(input);
|
||||
}
|
||||
} else {
|
||||
ChannelBuffer cumulation = cumulation(ctx);
|
||||
if (cumulation.readable()) {
|
||||
cumulation.discardReadBytes();
|
||||
cumulation.writeBytes(input);
|
||||
callDecode(ctx, e.getChannel(), cumulation, e.getRemoteAddress());
|
||||
} else {
|
||||
callDecode(ctx, e.getChannel(), input, e.getRemoteAddress());
|
||||
if (input.readable()) {
|
||||
cumulation.writeBytes(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -347,6 +358,12 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently used {@link ChannelBuffer} for cumulation or create one in a lazy fashion if none exist yet
|
||||
*
|
||||
* @param ctx the {@link ChannelHandlerContext} for this handler
|
||||
* @return buffer the {@link ChannelBuffer} which is used fo cumulation
|
||||
*/
|
||||
private ChannelBuffer cumulation(ChannelHandlerContext ctx) {
|
||||
ChannelBuffer c = cumulation;
|
||||
if (c == null) {
|
||||
|
Loading…
Reference in New Issue
Block a user