コード例 #1
0
ファイル: LocalChannel.java プロジェクト: 4T-Shirt/netty
    @Override
    public void connect(
        final SocketAddress remoteAddress,
        SocketAddress localAddress,
        final ChannelPromise promise) {
      if (!promise.setUncancellable() || !ensureOpen(promise)) {
        return;
      }

      if (state == State.CONNECTED) {
        Exception cause = new AlreadyConnectedException();
        safeSetFailure(promise, cause);
        pipeline().fireExceptionCaught(cause);
        return;
      }

      if (connectPromise != null) {
        throw new ConnectionPendingException();
      }

      connectPromise = promise;

      if (state != State.BOUND) {
        // Not bound yet and no localAddress specified - get one.
        if (localAddress == null) {
          localAddress = new LocalAddress(LocalChannel.this);
        }
      }

      if (localAddress != null) {
        try {
          doBind(localAddress);
        } catch (Throwable t) {
          safeSetFailure(promise, t);
          close(voidPromise());
          return;
        }
      }

      Channel boundChannel = LocalChannelRegistry.get(remoteAddress);
      if (!(boundChannel instanceof LocalServerChannel)) {
        Exception cause = new ChannelException("connection refused");
        safeSetFailure(promise, cause);
        close(voidPromise());
        return;
      }

      LocalServerChannel serverChannel = (LocalServerChannel) boundChannel;
      peer = serverChannel.serve(LocalChannel.this);
    }
コード例 #2
0
ファイル: LocalChannel.java プロジェクト: 4T-Shirt/netty
 LocalChannel(LocalServerChannel parent, EventLoop eventLoop, LocalChannel peer) {
   super(parent, eventLoop);
   this.peer = peer;
   localAddress = parent.localAddress();
   remoteAddress = peer.localAddress();
 }
コード例 #3
0
ファイル: LocalChannel.java プロジェクト: zhangjunfs/netty
 LocalChannel(LocalServerChannel parent, LocalChannel peer) {
   super(parent, null);
   this.peer = peer;
   localAddress = parent.localAddress();
   remoteAddress = peer.localAddress();
 }
コード例 #4
0
ファイル: LocalChannel.java プロジェクト: zhangjunfs/netty
    @Override
    public void connect(
        final SocketAddress remoteAddress, SocketAddress localAddress, final ChannelFuture future) {
      if (eventLoop().inEventLoop()) {
        if (!ensureOpen(future)) {
          return;
        }

        if (state == 2) {
          Exception cause = new AlreadyConnectedException();
          future.setFailure(cause);
          pipeline().fireExceptionCaught(cause);
          return;
        }

        if (connectFuture != null) {
          throw new ConnectionPendingException();
        }

        connectFuture = future;

        if (state != 1) {
          // Not bound yet and no localAddress specified - get one.
          if (localAddress == null) {
            localAddress = new LocalAddress(LocalChannel.this);
          }
        }

        if (localAddress != null) {
          try {
            doBind(localAddress);
          } catch (Throwable t) {
            future.setFailure(t);
            pipeline().fireExceptionCaught(t);
            close(voidFuture());
            return;
          }
        }

        Channel boundChannel = LocalChannelRegistry.get(remoteAddress);
        if (!(boundChannel instanceof LocalServerChannel)) {
          Exception cause = new ChannelException("connection refused");
          future.setFailure(cause);
          pipeline().fireExceptionCaught(cause);
          close(voidFuture());
          return;
        }

        LocalServerChannel serverChannel = (LocalServerChannel) boundChannel;
        peer = serverChannel.serve(LocalChannel.this);
      } else {
        final SocketAddress localAddress0 = localAddress;
        eventLoop()
            .execute(
                new Runnable() {
                  @Override
                  public void run() {
                    connect(remoteAddress, localAddress0, future);
                  }
                });
      }
    }