From 41d9830e077c6d3bf8ef23dfc1decb1d50059377 Mon Sep 17 00:00:00 2001 From: Scott Mitchell Date: Wed, 29 Oct 2014 14:12:10 -0400 Subject: [PATCH] SslHander wrap conditional direct buffer allocation Motivation: The SslHandler currently forces the use of a direct buffer for the input to the SSLEngine.wrap(..) operation. This allocation may not always be desired and should be conditionally done. Modifications: - Use the pre-existing wantsDirectBuffer variable as the condition to do the conversion. Result: - An allocation of a direct byte buffer and a copy of data is now not required for every SslHandler wrap operation. --- handler/src/main/java/io/netty/handler/ssl/SslHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/handler/src/main/java/io/netty/handler/ssl/SslHandler.java b/handler/src/main/java/io/netty/handler/ssl/SslHandler.java index f964d90568..4d5daaff12 100644 --- a/handler/src/main/java/io/netty/handler/ssl/SslHandler.java +++ b/handler/src/main/java/io/netty/handler/ssl/SslHandler.java @@ -176,7 +176,7 @@ public class SslHandler extends ByteToMessageDecoder { // BEGIN Platform-dependent flags /** - * {@code trus} if and only if {@link SSLEngine} expects a direct buffer. + * {@code true} if and only if {@link SSLEngine} expects a direct buffer. */ private final boolean wantsDirectBuffer; /** @@ -533,7 +533,7 @@ public class SslHandler extends ByteToMessageDecoder { ByteBuf newDirectIn = null; try { final ByteBuffer in0; - if (in.isDirect()) { + if (in.isDirect() || !wantsDirectBuffer) { in0 = in.nioBuffer(); } else { int readableBytes = in.readableBytes();