From db87c6ea3755a25c6fedff6f3f5bc5802ec5ffa6 Mon Sep 17 00:00:00 2001 From: norman Date: Wed, 4 Apr 2012 07:40:50 +0200 Subject: [PATCH] Make sure Channel connected event is not fired on connect failure. See #249 --- .../java/io/netty/channel/sctp/SctpWorker.java | 16 +++++++--------- .../io/netty/channel/socket/nio/NioWorker.java | 9 ++++----- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpWorker.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpWorker.java index 10f597fcad..2c11779ead 100644 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpWorker.java +++ b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpWorker.java @@ -215,7 +215,6 @@ public class SctpWorker extends NioWorker { protected void connect(SelectionKey k) { final SctpClientChannel ch = (SctpClientChannel) k.attachment(); try { - // TODO: Remove cast if (ch.getJdkChannel().finishConnect()) { registerTask(ch, ch.connectFuture); } @@ -358,7 +357,13 @@ public class SctpWorker extends NioWorker { ((SctpChannelImpl) channel).setConnected(); future.setSuccess(); } - + + if (!server) { + if (!((SctpClientChannel) channel).boundManually) { + fireChannelBound(channel, localAddress); + } + fireChannelConnected(channel, remoteAddress); + } } catch (IOException e) { if (future != null) { future.setFailure(e); @@ -369,13 +374,6 @@ public class SctpWorker extends NioWorker { "Failed to register a socket to the selector.", e); } } - - if (!server) { - if (!((SctpClientChannel) channel).boundManually) { - fireChannelBound(channel, localAddress); - } - fireChannelConnected(channel, remoteAddress); - } } @Override diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioWorker.java b/transport/src/main/java/io/netty/channel/socket/nio/NioWorker.java index 5da091776a..0f3ace41de 100644 --- a/transport/src/main/java/io/netty/channel/socket/nio/NioWorker.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/NioWorker.java @@ -140,6 +140,10 @@ public class NioWorker extends SelectorEventLoop { } future.setSuccess(); } + if (server || !((NioClientSocketChannel) channel).boundManually) { + fireChannelBound(channel, localAddress); + } + fireChannelConnected(channel, remoteAddress); } catch (IOException e) { if (future != null) { @@ -151,11 +155,6 @@ public class NioWorker extends SelectorEventLoop { "Failed to register a socket to the selector.", e); } } - - if (server || !((NioClientSocketChannel) channel).boundManually) { - fireChannelBound(channel, localAddress); - } - fireChannelConnected(channel, remoteAddress); } }