Skip to content

Commit

Permalink
Revert "SslHandler avoid calling wrap/unwrap when unnecessary"
Browse files Browse the repository at this point in the history
This reverts commit 6353c22 to "fix" [netty#6578].
  • Loading branch information
normanmaurer committed Apr 23, 2017
1 parent 1c63cc8 commit 7f3b75a
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions handler/src/main/java/io/netty/handler/ssl/SslHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ private void finishWrap(ChannelHandlerContext ctx, ByteBuf out, ChannelPromise p
* {@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 {
Expand All @@ -791,7 +791,7 @@ private boolean wrapNonAppData(ChannelHandlerContext ctx, boolean inUnwrap) thro
switch (result.getHandshakeStatus()) {
case FINISHED:
setHandshakeSuccess();
return false;
break;
case NEED_TASK:
runDelegatedTasks();
break;
Expand All @@ -809,7 +809,7 @@ private boolean wrapNonAppData(ChannelHandlerContext ctx, boolean inUnwrap) thro
if (!inUnwrap) {
unwrapNonAppData(ctx);
}
return true;
break;
default:
throw new IllegalStateException("Unknown handshake status: " + result.getHandshakeStatus());
}
Expand All @@ -829,7 +829,6 @@ private boolean wrapNonAppData(ChannelHandlerContext ctx, boolean inUnwrap) thro
out.release();
}
}
return false;
}

private SSLEngineResult wrap(ByteBufAllocator alloc, SSLEngine engine, ByteBuf in, ByteBuf out)
Expand Down Expand Up @@ -1153,7 +1152,7 @@ private boolean unwrap(
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();
Expand Down Expand Up @@ -1203,12 +1202,7 @@ private boolean unwrap(
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();
Expand Down Expand Up @@ -1241,12 +1235,7 @@ private boolean unwrap(
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);
Expand Down

0 comments on commit 7f3b75a

Please sign in to comment.