Esempio n. 1
0
  static void close(NioSocketChannel channel, ChannelFuture future) {
    NioWorker worker = channel.worker;

    boolean connected = channel.isConnected();
    boolean bound = channel.isBound();
    try {
      channel.socket.close();
      worker.cancelledKeys++;

      if (channel.setClosed()) {
        future.setSuccess();
        if (connected) {
          fireChannelDisconnected(channel);
        }
        if (bound) {
          fireChannelUnbound(channel);
        }

        cleanUpWriteBuffer(channel);
        fireChannelClosed(channel);
      } else {
        future.setSuccess();
      }
    } catch (Throwable t) {
      future.setFailure(t);
      fireExceptionCaught(channel, t);
    }
  }
Esempio n. 2
0
  static void write(final NioSocketChannel channel, boolean mightNeedWakeup) {
    if (!channel.isConnected()) {
      cleanUpWriteBuffer(channel);
      return;
    }

    if (mightNeedWakeup && scheduleWriteIfNecessary(channel)) {
      return;
    }

    if (channel.inWriteNowLoop) {
      scheduleWriteIfNecessary(channel);
    } else {
      writeNow(channel, channel.getConfig().getWriteSpinCount());
    }
  }