Only send event upstream once the Ssl handshake was completed successfull. See #358

This commit is contained in:
Norman Maurer 2012-05-22 22:57:36 +02:00
parent bd4358b3ad
commit 03f890a882

View File

@ -197,16 +197,6 @@ public class SslHandler extends FrameDecoder
private final NonReentrantLock pendingEncryptedWritesLock = new NonReentrantLock(); private final NonReentrantLock pendingEncryptedWritesLock = new NonReentrantLock();
private volatile boolean issueHandshake; private volatile boolean issueHandshake;
private static final ChannelFutureListener HANDSHAKE_LISTENER = new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
Channels.fireExceptionCaught(future.getChannel(), future.getCause());
}
}
};
private final SSLEngineInboundCloseFuture sslEngineCloseFuture = new SSLEngineInboundCloseFuture(); private final SSLEngineInboundCloseFuture sslEngineCloseFuture = new SSLEngineInboundCloseFuture();
@ -1270,13 +1260,26 @@ public class SslHandler extends FrameDecoder
* Calls {@link #handshake()} once the {@link Channel} is connected * Calls {@link #handshake()} once the {@link Channel} is connected
*/ */
@Override @Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { public void channelConnected(final ChannelHandlerContext ctx, final ChannelStateEvent e) throws Exception {
if (issueHandshake) { if (issueHandshake) {
// issue and handshake and add a listener to it which will fire an exception event if an exception was thrown // issue and handshake and add a listener to it which will fire an exception event if an exception was thrown while doing the handshake
// while doing the handshake handshake().addListener(new ChannelFutureListener() {
handshake().addListener(HANDSHAKE_LISTENER);
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
Channels.fireExceptionCaught(future.getChannel(), future.getCause());
} else {
// Send the event upstream after the handshake was completed without an error.
//
// See https://github.com/netty/netty/issues/358
ctx.sendUpstream(e);
}
}
});
} else {
super.channelConnected(ctx, e);
} }
super.channelConnected(ctx, e);
} }
/** /**