From 5852d82ad6d756da9ef53ea570b4afe4e153df63 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Tue, 22 May 2012 22:57:36 +0200 Subject: [PATCH] Only send event upstream once the Ssl handshake was completed successfull. See #358 Conflicts: handler/src/main/java/io/netty/handler/ssl/SslHandler.java --- .../java/io/netty/handler/ssl/SslHandler.java | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 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 245e5b3dc1..9c574b76bc 100644 --- a/handler/src/main/java/io/netty/handler/ssl/SslHandler.java +++ b/handler/src/main/java/io/netty/handler/ssl/SslHandler.java @@ -187,17 +187,6 @@ public class SslHandler extends FrameDecoder private final NonReentrantLock pendingEncryptedWritesLock = new NonReentrantLock(); 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.channel(), future.cause()); - } - } - - }; - private final SSLEngineInboundCloseFuture sslEngineCloseFuture = new SSLEngineInboundCloseFuture(); /** @@ -840,14 +829,7 @@ public class SslHandler extends FrameDecoder if (result.bytesProduced() > 0) { outNetBuf.flip(); -<<<<<<< HEAD ChannelBuffer msg = ChannelBuffers.buffer(outNetBuf.remaining()); - -======= - ChannelBuffer msg = ctx.getChannel().getConfig().getBufferFactory().getBuffer(outNetBuf.remaining()); - - ->>>>>>> d2ec45e... Use the correct ChannelBufferFactory when creating new ChannelBuffers. See #335 // Transfer the bytes to the new ChannelBuffer using some safe method that will also // work with "non" heap buffers // @@ -1259,13 +1241,27 @@ public class SslHandler extends FrameDecoder * Calls {@link #handshake()} once the {@link Channel} is connected */ @Override - public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { + public void channelConnected(final ChannelHandlerContext ctx, final ChannelStateEvent e) throws Exception { if (issueHandshake) { - // issue and handshake and add a listener to it which will fire an exception event if an exception was thrown - // while doing the handshake - handshake().addListener(HANDSHAKE_LISTENER); + // issue and handshake and add a listener to it which will fire an exception event if an exception was thrown while doing the handshake + handshake().addListener(new ChannelFutureListener() { + + @Override + 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); } /**