From 7f3b75a5091dcd6d882102fdb92daa6931e02c30 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Sun, 23 Apr 2017 21:08:03 +0200 Subject: [PATCH] Revert "SslHandler avoid calling wrap/unwrap when unnecessary" This reverts commit 6353c229fd11c6e6306011d55993775f7685d122 to "fix" [#6578]. --- .../java/io/netty/handler/ssl/SslHandler.java | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 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 048bf8a22c..4855c03623 100644 --- a/handler/src/main/java/io/netty/handler/ssl/SslHandler.java +++ b/handler/src/main/java/io/netty/handler/ssl/SslHandler.java @@ -765,7 +765,7 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH * {@link #setHandshakeFailure(ChannelHandlerContext, Throwable)}. * @return {@code true} if this method ends on {@link SSLEngineResult.HandshakeStatus#NOT_HANDSHAKING}. */ - private boolean wrapNonAppData(ChannelHandlerContext ctx, boolean inUnwrap) throws SSLException { + private void wrapNonAppData(ChannelHandlerContext ctx, boolean inUnwrap) throws SSLException { ByteBuf out = null; ByteBufAllocator alloc = ctx.alloc(); try { @@ -791,7 +791,7 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH switch (result.getHandshakeStatus()) { case FINISHED: setHandshakeSuccess(); - return false; + break; case NEED_TASK: runDelegatedTasks(); break; @@ -809,7 +809,7 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH if (!inUnwrap) { unwrapNonAppData(ctx); } - return true; + break; default: throw new IllegalStateException("Unknown handshake status: " + result.getHandshakeStatus()); } @@ -829,7 +829,6 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH out.release(); } } - return false; } private SSLEngineResult wrap(ByteBufAllocator alloc, SSLEngine engine, ByteBuf in, ByteBuf out) @@ -1153,7 +1152,7 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH try { // Only continue to loop if the handler was not removed in the meantime. // See https://github.com/netty/netty/issues/5860 - unwrapLoop: while (!ctx.isRemoved()) { + while (!ctx.isRemoved()) { final SSLEngineResult result = engineType.unwrap(this, packet, offset, length, decodeOut); final Status status = result.getStatus(); final HandshakeStatus handshakeStatus = result.getHandshakeStatus(); @@ -1203,12 +1202,7 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH case NEED_UNWRAP: break; case NEED_WRAP: - // If the wrap operation transitions the status to NOT_HANDSHAKING and there is no more data to - // unwrap then the next call to unwrap will not produce any data. We can avoid the potentially - // costly unwrap operation and break out of the loop. - if (wrapNonAppData(ctx, true) && length == 0) { - break unwrapLoop; - } + wrapNonAppData(ctx, true); break; case NEED_TASK: runDelegatedTasks(); @@ -1241,12 +1235,7 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH flushedBeforeHandshake = false; wrapLater = true; } - // If we are not handshaking and there is no more data to unwrap then the next call to unwrap - // will not produce any data. We can avoid the potentially costly unwrap operation and break - // out of the loop. - if (length == 0) { - break unwrapLoop; - } + break; default: throw new IllegalStateException("unknown handshake status: " + handshakeStatus);