From d1e63281021033714e742ba0bbce3d563ee1264c Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Thu, 3 May 2012 17:15:03 +0200 Subject: [PATCH] Allow to register ChannelFutureListener's that get notified once the inbound of the SSLEngine is closed. See #137 --- .../java/io/netty/handler/ssl/SslHandler.java | 52 ++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) 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 5000957458..2e7befe6ed 100644 --- a/handler/src/main/java/io/netty/handler/ssl/SslHandler.java +++ b/handler/src/main/java/io/netty/handler/ssl/SslHandler.java @@ -43,6 +43,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelStateEvent; import io.netty.channel.Channels; +import io.netty.channel.DefaultChannelFuture; import io.netty.channel.DownstreamMessageEvent; import io.netty.channel.ExceptionEvent; import io.netty.channel.LifeCycleAwareChannelHandler; @@ -207,6 +208,8 @@ public class SslHandler extends FrameDecoder }; + private final SSLEngineInboundCloseFuture sslEngineCloseFuture = new SSLEngineInboundCloseFuture(); + /** * Creates a new instance. * @@ -426,6 +429,18 @@ public class SslHandler extends FrameDecoder return issueHandshake; } + /** + * Return the {@link ChannelFuture} that will get notified if the inbound of the {@link SSLEngine} will get closed. + * + * This method will return the same {@link ChannelFuture} all the time. + * + * For more informations see the apidocs of {@link SSLEngine} + * + */ + public ChannelFuture getSSLEngineInboundCloseFuture() { + return sslEngineCloseFuture; + } + @Override public void handleDownstream( final ChannelHandlerContext context, final ChannelEvent evt) throws Exception { @@ -924,7 +939,12 @@ public class SslHandler extends FrameDecoder synchronized (handshakeLock) { result = engine.unwrap(inNetBuf, outAppBuf); } - + + // notify about the CLOSED state of the SSLEngine. See #137 + if (result.getStatus() == Status.CLOSED) { + sslEngineCloseFuture.setClosed(); + } + final HandshakeStatus handshakeStatus = result.getHandshakeStatus(); handleRenegotiation(handshakeStatus); switch (handshakeStatus) { @@ -1209,4 +1229,34 @@ public class SslHandler extends FrameDecoder } super.channelConnected(ctx, e); } + + private final class SSLEngineInboundCloseFuture extends DefaultChannelFuture { + public SSLEngineInboundCloseFuture() { + super(null, true); + } + + void setClosed() { + super.setSuccess(); + } + + @Override + public Channel getChannel() { + if (ctx == null) { + // Maybe we should better throw an IllegalStateException() ? + return null; + } else { + return ctx.getChannel(); + } + } + + @Override + public boolean setSuccess() { + return false; + } + + @Override + public boolean setFailure(Throwable cause) { + return false; + } + } }