private void bind( NioClientSocketChannel channel, ChannelFuture future, SocketAddress localAddress) { try { channel.getJdkChannel().bind(localAddress); channel.boundManually = true; channel.setBound(); future.setSuccess(); fireChannelBound(channel, channel.getLocalAddress()); } catch (Throwable t) { future.setFailure(t); fireExceptionCaught(channel, t); } }
@Override public void run() { SocketAddress localAddress = channel.getLocalAddress(); SocketAddress remoteAddress = channel.getRemoteAddress(); if (localAddress == null || remoteAddress == null) { if (future != null) { future.setFailure(new ClosedChannelException()); } close(channel, succeededFuture(channel)); return; } try { if (server) { channel.channel.configureBlocking(false); } synchronized (channel.interestOpsLock) { channel.channel.register(selector, channel.getRawInterestOps(), channel); } channel.setConnected(); if (future != null) { future.setSuccess(); } } catch (IOException e) { if (future != null) { future.setFailure(e); } close(channel, succeededFuture(channel)); if (!(e instanceof ClosedChannelException)) { throw new ChannelException("Failed to register a socket to the selector.", e); } } if (!server) { if (!((SctpClientChannel) channel).boundManually) { fireChannelBound(channel, localAddress); } fireChannelConnected(channel, remoteAddress); } }
private void bind( SctpServerChannelImpl channel, ChannelFuture future, SocketAddress localAddress) { boolean bound = false; boolean bossStarted = false; try { channel.serverChannel.bind(localAddress, channel.getConfig().getBacklog()); bound = true; channel.setBound(); future.setSuccess(); fireChannelBound(channel, channel.getLocalAddress()); Executor bossExecutor = ((SctpServerSocketChannelFactory) channel.getFactory()).bossExecutor; DeadLockProofWorker.start(bossExecutor, new Boss(channel)); bossStarted = true; } catch (Throwable t) { future.setFailure(t); fireExceptionCaught(channel, t); } finally { if (!bossStarted && bound) { close(channel, future); } } }