Correctly calculate the writable bytes and use a heap buffer to hold the bytes that are left
This commit is contained in:
parent
33715ede50
commit
d126059fb4
@ -215,7 +215,7 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler {
|
||||
|
||||
int readable = input.readableBytes();
|
||||
int writable = cumulation.writableBytes();
|
||||
int w = readable - writable;
|
||||
int w = writable - readable;
|
||||
if (w < 0) {
|
||||
int readerIndex = cumulation.readerIndex();
|
||||
if (w + readerIndex >= 0) {
|
||||
@ -224,10 +224,12 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler {
|
||||
fit = true;
|
||||
}
|
||||
} else {
|
||||
|
||||
// ok the input fit into the cumulation buffer
|
||||
fit = true;
|
||||
}
|
||||
|
||||
|
||||
ChannelBuffer buf;
|
||||
if (fit) {
|
||||
// the input fit in the cumulation buffer so copy it over
|
||||
@ -380,17 +382,15 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler {
|
||||
|
||||
/**
|
||||
* Create a new {@link ChannelBuffer} which is used for the cumulation.
|
||||
* Be aware that this MUST be a dynamic buffer. Sub-classes may override
|
||||
* this to provide a dynamic {@link ChannelBuffer} which has some
|
||||
* pre-allocated size that better fit their need.
|
||||
*
|
||||
* Sub-classes may override this.
|
||||
*
|
||||
* @param ctx {@link ChannelHandlerContext} for this handler
|
||||
* @return buffer the {@link ChannelBuffer} which is used for cumulation
|
||||
*/
|
||||
protected ChannelBuffer newCumulationBuffer(
|
||||
ChannelHandlerContext ctx, int minimumCapacity) {
|
||||
ChannelBufferFactory factory = ctx.getChannel().getConfig().getBufferFactory();
|
||||
return ChannelBuffers.dynamicBuffer(
|
||||
factory.getDefaultOrder(), Math.max(minimumCapacity, 256), factory);
|
||||
return ChannelBuffers.buffer(
|
||||
factory.getDefaultOrder(), Math.max(minimumCapacity, 256));
|
||||
}
|
||||
}
|
||||
|
@ -479,7 +479,7 @@ public abstract class ReplayingDecoder<T extends Enum<T>>
|
||||
|
||||
int readable = input.readableBytes();
|
||||
int writable = cumulation.writableBytes();
|
||||
int w = readable - writable;
|
||||
int w = writable - readable;
|
||||
if (w < 0) {
|
||||
int readerIndex = cumulation.readerIndex();
|
||||
if (w + readerIndex >= 0) {
|
||||
@ -488,6 +488,7 @@ public abstract class ReplayingDecoder<T extends Enum<T>>
|
||||
fit = true;
|
||||
}
|
||||
} else {
|
||||
|
||||
// ok the input fit into the cumulation buffer
|
||||
fit = true;
|
||||
}
|
||||
@ -638,9 +639,7 @@ public abstract class ReplayingDecoder<T extends Enum<T>>
|
||||
|
||||
/**
|
||||
* Create a new {@link ChannelBuffer} which is used for the cumulation.
|
||||
* Be aware that this MUST be a dynamic buffer. Sub-classes may override
|
||||
* this to provide a dynamic {@link ChannelBuffer} which has some
|
||||
* pre-allocated size that better fit their need.
|
||||
* Sub-classes may override this.
|
||||
*
|
||||
* @param ctx {@link ChannelHandlerContext} for this handler
|
||||
* @return buffer the {@link ChannelBuffer} which is used for cumulation
|
||||
@ -648,7 +647,7 @@ public abstract class ReplayingDecoder<T extends Enum<T>>
|
||||
protected ChannelBuffer newCumulationBuffer(
|
||||
ChannelHandlerContext ctx, int minimumCapacity) {
|
||||
ChannelBufferFactory factory = ctx.getChannel().getConfig().getBufferFactory();
|
||||
return ChannelBuffers.dynamicBuffer(
|
||||
factory.getDefaultOrder(), Math.max(minimumCapacity, 256), factory);
|
||||
return ChannelBuffers.buffer(
|
||||
factory.getDefaultOrder(), Math.max(minimumCapacity, 256));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user