From 8490d611bf21ee9436e7575157f7f6d13cf5e30f Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 5 Feb 2016 12:50:42 +1100 Subject: [PATCH] [#1717] Perform a copy if Netty isn't using a direct address for any reason. --- .../bungee/protocol/Varint21FrameDecoder.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java b/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java index d9f6d52e..3a43179b 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java @@ -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 out) throws Exception { @@ -40,8 +42,22 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder return; } else { - out.add( in.slice( in.readerIndex(), length ).retain() ); - in.skipBytes( length ); + 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; } }