Example #1
0
 private void registerAcceptedChannel(SctpChannel acceptedSocket, Thread currentThread) {
   try {
     ChannelPipeline pipeline = channel.getConfig().getPipelineFactory().getPipeline();
     SctpWorker worker = nextWorker();
     worker.register(
         new SctpAcceptedChannel(
             channel.getFactory(),
             pipeline,
             channel,
             SctpServerPipelineSink.this,
             acceptedSocket,
             worker,
             currentThread),
         null);
   } catch (Exception e) {
     if (logger.isWarnEnabled()) {
       logger.warn("Failed to initialize an accepted socket.", e);
     }
     try {
       acceptedSocket.close();
     } catch (IOException e2) {
       if (logger.isWarnEnabled()) {
         logger.warn("Failed to close a partially accepted socket.", e2);
       }
     }
   }
 }
Example #2
0
  private void close(SctpServerChannelImpl channel, ChannelFuture future) {
    boolean bound = channel.isBound();
    try {
      if (channel.serverChannel.isOpen()) {
        channel.serverChannel.close();
        Selector selector = channel.selector;
        if (selector != null) {
          selector.wakeup();
        }
      }

      // Make sure the boss thread is not running so that that the future
      // is notified after a new connection cannot be accepted anymore.
      // See NETTY-256 for more information.
      channel.shutdownLock.lock();
      try {
        if (channel.setClosed()) {
          future.setSuccess();
          if (bound) {
            fireChannelUnbound(channel);
          }
          fireChannelClosed(channel);
        } else {
          future.setSuccess();
        }
      } finally {
        channel.shutdownLock.unlock();
      }
    } catch (Throwable t) {
      future.setFailure(t);
      fireExceptionCaught(channel, t);
    }
  }
Example #3
0
 private void closeSelector() {
   channel.selector = null;
   try {
     selector.close();
   } catch (Exception e) {
     if (logger.isWarnEnabled()) {
       logger.warn("Failed to close a selector.", e);
     }
   }
 }
Example #4
0
  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);
      }
    }
  }
Example #5
0
    Boss(SctpServerChannelImpl channel) throws IOException {
      this.channel = channel;

      selector = Selector.open();

      boolean registered = false;
      try {
        channel.serverChannel.register(selector, SelectionKey.OP_ACCEPT);
        registered = true;
      } finally {
        if (!registered) {
          closeSelector();
        }
      }

      channel.selector = selector;
    }