コード例 #1
0
    /** Connect to the remote peer */
    private boolean doConnect(InetSocketAddress remoteAddress, InetSocketAddress localAddress)
        throws Exception {
      if (localAddress != null) {
        checkResolvable(localAddress);
        Native.bind(fd, localAddress.getAddress(), localAddress.getPort());
      }

      boolean success = false;
      try {
        checkResolvable(remoteAddress);
        boolean connected = Native.connect(fd, remoteAddress.getAddress(), remoteAddress.getPort());
        remote = remoteAddress;
        local = Native.localAddress(fd);
        if (!connected) {
          setEpollOut();
        }
        success = true;
        return connected;
      } finally {
        if (!success) {
          doClose();
        }
      }
    }
コード例 #2
0
 @Override
 protected void doBind(SocketAddress local) throws Exception {
   InetSocketAddress localAddress = (InetSocketAddress) local;
   Native.bind(fd, localAddress.getAddress(), localAddress.getPort());
   this.local = Native.localAddress(fd);
 }