[#1717] Perform a copy if Netty isn't using a direct address for any reason.

This commit is contained in:
md_5 2016-02-05 12:50:42 +11:00
parent a0f2c42d38
commit 8490d611bf

View File

@ -11,6 +11,8 @@ import java.util.List;
public class Varint21FrameDecoder extends ByteToMessageDecoder
{
private static boolean DIRECT_WARNING;
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
{
@ -39,9 +41,23 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
in.resetReaderIndex();
return;
} else
{
if ( in.hasMemoryAddress() )
{
out.add( in.slice( in.readerIndex(), length ).retain() );
in.skipBytes( length );
} else
{
if ( !DIRECT_WARNING )
{
DIRECT_WARNING = true;
System.err.println( "[WARN] Netty is not using direct IO buffers." );
}
ByteBuf dst = ctx.alloc().directBuffer( length );
in.readBytes( dst );
out.add( dst );
}
return;
}
}