/** * Connects socket 'fd' to 'inetAddress' on 'port', with no timeout. The lack of a timeout * means this method won't throw SocketTimeoutException. */ public static boolean connect(FileDescriptor fd, InetAddress inetAddress, int port) throws SocketException { try { return IoBridge.connect(fd, inetAddress, port, 0); } catch (SocketTimeoutException ex) { throw new AssertionError(ex); // Can't happen for a connect without a timeout. } }
@Override public void connect(InetAddress inetAddr, int port) throws SocketException { IoBridge.connect(fd, inetAddr, port); // Throws on failure. try { connectedAddress = InetAddress.getByAddress(inetAddr.getAddress()); } catch (UnknownHostException e) { // this is never expected to happen as we should not have gotten // here if the address is not resolvable throw new SocketException("Host is unresolved: " + inetAddr.getHostName()); } connectedPort = port; isNativeConnected = true; }
/** * Connects this socket to the specified remote host address/port. * * @param anAddr * the remote host address to connect to * @param aPort * the remote port to connect to * @param timeout * a timeout where supported. 0 means no timeout * @throws IOException * if an error occurs while connecting */ private void connect(InetAddress anAddr, int aPort, int timeout) throws IOException { InetAddress normalAddr = anAddr.isAnyLocalAddress() ? InetAddress.getLocalHost() : anAddr; if (streaming && usingSocks()) { socksConnect(anAddr, aPort, 0); } else { IoBridge.connect(fd, normalAddr, aPort, timeout); } super.address = normalAddr; super.port = aPort; }
/** * Connect using a SOCKS server. */ private void socksConnect(InetAddress applicationServerAddress, int applicationServerPort, int timeout) throws IOException { try { IoBridge.connect(fd, socksGetServerAddress(), socksGetServerPort(), timeout); } catch (Exception e) { throw new SocketException("SOCKS connection failed", e); } socksRequestConnection(applicationServerAddress, applicationServerPort); lastConnectedAddress = applicationServerAddress; lastConnectedPort = applicationServerPort; }
private boolean isReachable(InetAddress destination, InetAddress source, int timeout) throws IOException { // TODO: try ICMP first (http://code.google.com/p/android/issues/detail?id=20106) FileDescriptor fd = IoBridge.socket(true); boolean reached = false; try { if (source != null) { IoBridge.bind(fd, source, 0); } IoBridge.connect(fd, destination, 7, timeout); reached = true; } catch (IOException e) { if (e.getCause() instanceof ErrnoException) { // "Connection refused" means the IP address was reachable. reached = (((ErrnoException) e.getCause()).errno == ECONNREFUSED); } } IoBridge.closeSocket(fd); return reached; }
/** * @see java.nio.channels.DatagramChannel#connect(java.net.SocketAddress) */ @Override synchronized public DatagramChannel connect(SocketAddress address) throws IOException { // must open checkOpen(); // status must be un-connected. if (connected) { throw new IllegalStateException(); } // check the address InetSocketAddress inetSocketAddress = SocketChannelImpl.validateAddress(address); try { begin(); IoBridge.connect(fd, inetSocketAddress.getAddress(), inetSocketAddress.getPort()); } catch (ConnectException e) { // ConnectException means connect fail, not exception } finally { end(true); } // set the connected address. connectAddress = inetSocketAddress; connected = true; isBound = true; return this; }
begin(); finished = IoBridge.connect(fd, normalAddr, port); isBound = finished; } catch (IOException e) {
IoBridge.connect(fd, socksGetServerAddress(), socksGetServerPort()); } catch (Exception e) { throw new IOException("Unable to connect to SOCKS server", e);
/** * Connects socket 'fd' to 'inetAddress' on 'port', with no timeout. The lack of a timeout * means this method won't throw SocketTimeoutException. */ public static boolean connect(FileDescriptor fd, InetAddress inetAddress, int port) throws SocketException { try { return IoBridge.connect(fd, inetAddress, port, 0); } catch (SocketTimeoutException ex) { throw new AssertionError(ex); // Can't happen for a connect without a timeout. } }
/** * Connects socket 'fd' to 'inetAddress' on 'port', with no timeout. The lack of a timeout * means this method won't throw SocketTimeoutException. */ public static boolean connect(FileDescriptor fd, InetAddress inetAddress, int port) throws SocketException { try { return IoBridge.connect(fd, inetAddress, port, 0); } catch (SocketTimeoutException ex) { throw new AssertionError(ex); // Can't happen for a connect without a timeout. } }
/** * Connects socket 'fd' to 'inetAddress' on 'port', with no timeout. The lack of a timeout * means this method won't throw SocketTimeoutException. */ public static boolean connect(FileDescriptor fd, InetAddress inetAddress, int port) throws SocketException { try { return IoBridge.connect(fd, inetAddress, port, 0); } catch (SocketTimeoutException ex) { throw new AssertionError(ex); // Can't happen for a connect without a timeout. } }
/** * Connects socket 'fd' to 'inetAddress' on 'port', with no timeout. The lack of a timeout * means this method won't throw SocketTimeoutException. */ public static boolean connect(FileDescriptor fd, InetAddress inetAddress, int port) throws SocketException { try { return IoBridge.connect(fd, inetAddress, port, 0); } catch (SocketTimeoutException ex) { throw new AssertionError(ex); // Can't happen for a connect without a timeout. } }
/** * Connects socket 'fd' to 'inetAddress' on 'port', with no timeout. The lack of a timeout * means this method won't throw SocketTimeoutException. */ public static boolean connect(FileDescriptor fd, InetAddress inetAddress, int port) throws SocketException { try { return IoBridge.connect(fd, inetAddress, port, 0); } catch (SocketTimeoutException ex) { throw new AssertionError(ex); // Can't happen for a connect without a timeout. } }
/** * Connects socket 'fd' to 'inetAddress' on 'port', with no timeout. The lack of a timeout * means this method won't throw SocketTimeoutException. */ public static boolean connect(FileDescriptor fd, InetAddress inetAddress, int port) throws SocketException { try { return IoBridge.connect(fd, inetAddress, port, 0); } catch (SocketTimeoutException ex) { throw new AssertionError(ex); // Can't happen for a connect without a timeout. } }
@Override public void connect(InetAddress inetAddr, int port) throws SocketException { IoBridge.connect(fd, inetAddr, port); // Throws on failure. try { connectedAddress = InetAddress.getByAddress(inetAddr.getAddress()); } catch (UnknownHostException e) { // this is never expected to happen as we should not have gotten // here if the address is not resolvable throw new SocketException("Host is unresolved: " + inetAddr.getHostName()); } connectedPort = port; isNativeConnected = true; }
@Override public void connect(InetAddress inetAddr, int port) throws SocketException { IoBridge.connect(fd, inetAddr, port); // Throws on failure. try { connectedAddress = InetAddress.getByAddress(inetAddr.getAddress()); } catch (UnknownHostException e) { // this is never expected to happen as we should not have gotten // here if the address is not resolvable throw new SocketException("Host is unresolved: " + inetAddr.getHostName()); } connectedPort = port; isNativeConnected = true; }
@Override public void connect(InetAddress inetAddr, int port) throws SocketException { IoBridge.connect(fd, inetAddr, port); // Throws on failure. try { connectedAddress = InetAddress.getByAddress(inetAddr.getAddress()); } catch (UnknownHostException e) { // this is never expected to happen as we should not have gotten // here if the address is not resolvable throw new SocketException("Host is unresolved: " + inetAddr.getHostName()); } connectedPort = port; isNativeConnected = true; }
/** * Connect using a SOCKS server. */ private void socksConnect(InetAddress applicationServerAddress, int applicationServerPort, int timeout) throws IOException { try { IoBridge.connect(fd, socksGetServerAddress(), socksGetServerPort(), timeout); } catch (Exception e) { throw new SocketException("SOCKS connection failed", e); } socksRequestConnection(applicationServerAddress, applicationServerPort); lastConnectedAddress = applicationServerAddress; lastConnectedPort = applicationServerPort; }
/** * Connect using a SOCKS server. */ private void socksConnect(InetAddress applicationServerAddress, int applicationServerPort, int timeout) throws IOException { try { IoBridge.connect(fd, socksGetServerAddress(), socksGetServerPort(), timeout); } catch (Exception e) { throw new SocketException("SOCKS connection failed", e); } socksRequestConnection(applicationServerAddress, applicationServerPort); lastConnectedAddress = applicationServerAddress; lastConnectedPort = applicationServerPort; }
/** * Connect using a SOCKS server. */ private void socksConnect(InetAddress applicationServerAddress, int applicationServerPort, int timeout) throws IOException { try { IoBridge.connect(fd, socksGetServerAddress(), socksGetServerPort(), timeout); } catch (Exception e) { throw new SocketException("SOCKS connection failed", e); } socksRequestConnection(applicationServerAddress, applicationServerPort); lastConnectedAddress = applicationServerAddress; lastConnectedPort = applicationServerPort; }