Make sure the cumulation Buffer is only created if really needed. See
#88
This commit is contained in:
parent
55e7a85160
commit
0d5c7d3d2e
@ -205,6 +205,15 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
@ -218,6 +227,8 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelDisconnected(
|
||||
ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
|
||||
@ -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