Rename SslHandler.close(...) to closeOutbound(...) as it is still useful and delegate to the methods. (#8193)

* Rename SslHandler.close(...) to closeOutbound(...) as it is still useful and delegate to the methods.

Motivation:

Sometimes the user may want to send a close_notify without closing the underlying Channel. For this we offered the SslHandler.close(...) methods which were marked as deeprecated. We should offer an way to still do this without the user calling deprecated methods.

See https://stackoverflow.com/questions/51710231/using-nettys-sslhandlerclosechannelhandlercontext-channelpromise/51753742#comment90555949_51753742 .

Modifications:

- Remove deprecation of the SslHandler.close(...) method that exactly allows this and rename these to closeOutbound(...) as this is more clear.
- Add close(...) methods that delegate to these and mark these as deprecated.

Result:

Be able to send close_notify without closing the Channel.
This commit is contained in:
Norman Maurer 2018-08-15 20:07:56 +02:00 committed by GitHub
parent 2fa7a0aa57
commit 8255f85f24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -93,7 +93,7 @@ import static io.netty.handler.ssl.SslUtils.getEncryptedPacketLength;
* *
* <h3>Closing the session</h3> * <h3>Closing the session</h3>
* <p> * <p>
* To close the SSL session, the {@link #close()} method should be * To close the SSL session, the {@link #closeOutbound()} method should be
* called to send the {@code close_notify} message to the remote peer. One * called to send the {@code close_notify} message to the remote peer. One
* exception is when you close the {@link Channel} - {@link SslHandler} * exception is when you close the {@link Channel} - {@link SslHandler}
* intercepts the close request and send the {@code close_notify} message * intercepts the close request and send the {@code close_notify} message
@ -622,27 +622,53 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
} }
/** /**
* Sends an SSL {@code close_notify} message to the specified channel and * Use {@link #closeOutbound()}
* destroys the underlying {@link SSLEngine}.
*
* @deprecated use {@link Channel#close()} or {@link ChannelHandlerContext#close()}
*/ */
@Deprecated @Deprecated
public ChannelFuture close() { public ChannelFuture close() {
return close(ctx.newPromise()); return closeOutbound();
} }
/** /**
* See {@link #close()} * Use {@link #closeOutbound(ChannelPromise)}
*
* @deprecated use {@link Channel#close()} or {@link ChannelHandlerContext#close()}
*/ */
@Deprecated @Deprecated
public ChannelFuture close(final ChannelPromise promise) { public ChannelFuture close(ChannelPromise promise) {
return closeOutbound(promise);
}
/**
* Sends an SSL {@code close_notify} message to the specified channel and
* destroys the underlying {@link SSLEngine}. This will <strong>not</strong> close the underlying
* {@link Channel}. If you want to also close the {@link Channel} use {@link Channel#close()} or
* {@link ChannelHandlerContext#close()}
*/
public ChannelFuture closeOutbound() {
return closeOutbound(ctx.newPromise());
}
/**
* Sends an SSL {@code close_notify} message to the specified channel and
* destroys the underlying {@link SSLEngine}. This will <strong>not</strong> close the underlying
* {@link Channel}. If you want to also close the {@link Channel} use {@link Channel#close()} or
* {@link ChannelHandlerContext#close()}
*/
public ChannelFuture closeOutbound(final ChannelPromise promise) {
final ChannelHandlerContext ctx = this.ctx; final ChannelHandlerContext ctx = this.ctx;
if (ctx.executor().inEventLoop()) {
closeOutbound0(promise);
} else {
ctx.executor().execute(new Runnable() { ctx.executor().execute(new Runnable() {
@Override @Override
public void run() { public void run() {
closeOutbound0(promise);
}
});
}
return promise;
}
private void closeOutbound0(ChannelPromise promise) {
outboundClosed = true; outboundClosed = true;
engine.closeOutbound(); engine.closeOutbound();
try { try {
@ -653,10 +679,6 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
} }
} }
} }
});
return promise;
}
/** /**
* Return the {@link Future} that will get notified if the inbound of the {@link SSLEngine} is closed. * Return the {@link Future} that will get notified if the inbound of the {@link SSLEngine} is closed.