private static int maybeThrowAfterRecvfrom(boolean isRead, boolean isConnected, ErrnoException errnoException) throws SocketException, SocketTimeoutException { if (isRead) { if (errnoException.errno == EAGAIN) { return 0; } else { throw errnoException.rethrowAsSocketException(); } } else { if (isConnected && errnoException.errno == ECONNREFUSED) { throw new PortUnreachableException("", errnoException); } else if (errnoException.errno == EAGAIN) { throw new SocketTimeoutException(errnoException); } else { throw errnoException.rethrowAsSocketException(); } } }
ConnectDatum tryConnect(SocketChannel dstSocket) { // Package visibility for testing purposes. final Timer timer = new Timer(); try { dstSocket.connect(dst); return new ConnectDatum(ConnectResult.OK, timer.getAsLong(), Optional.empty()); } catch (SocketTimeoutException | ClosedByInterruptException ex) { return new ConnectDatum(ConnectResult.TIMED_OUT, timer.getAsLong(), Optional.ofNullable(ex.getMessage())); } catch (NoRouteToHostException ex) { return new ConnectDatum(ConnectResult.NO_ROUTE_TO_HOST, timer.getAsLong(), Optional.ofNullable(ex.getMessage())); } catch (PortUnreachableException ex) { return new ConnectDatum(ConnectResult.PORT_UNREACHABLE, timer.getAsLong(), Optional.ofNullable(ex.getMessage())); } catch (UnknownHostException ex) { return new ConnectDatum(ConnectResult.UNKNOWN_HOST, timer.getAsLong(), Optional.ofNullable(ex.getMessage())); } catch (UnknownServiceException ex) { return new ConnectDatum(ConnectResult.UNKNOWN_SERVICE, timer.getAsLong(), Optional.ofNullable(ex.getMessage())); } catch (ProtocolException ex) { return new ConnectDatum(ConnectResult.PROTOCOL_ERROR, timer.getAsLong(), Optional.ofNullable(ex.getMessage())); } catch (BindException ex) { return new ConnectDatum(ConnectResult.BIND_FAILED, timer.getAsLong(), Optional.ofNullable(ex.getMessage())); } catch (ConnectException ex) { // ConnectException and SocketException seem to cover the same error cases..? return new ConnectDatum(ConnectResult.CONNECT_FAILED, timer.getAsLong(), Optional.ofNullable(ex.getMessage())); } catch (SocketException ex) { // ConnectException and SocketException seem to cover the same error cases..? return new ConnectDatum(ConnectResult.CONNECT_FAILED, timer.getAsLong(), Optional.ofNullable(ex.getMessage())); } catch (IOException ex) { return new ConnectDatum(ConnectResult.IO_ERROR, timer.getAsLong(), Optional.ofNullable(ex.getMessage())); } }
public final int sendTo(ByteBuffer buf, int pos, int limit, InetAddress addr, int port) throws IOException { // just duplicate the toNativeInetAddress code here to minimize object creation as this method is expected // to be called frequently byte[] address; int scopeId; if (addr instanceof Inet6Address) { address = addr.getAddress(); scopeId = ((Inet6Address) addr).getScopeId(); } else { // convert to ipv4 mapped ipv6 address; scopeId = 0; address = ipv4MappedIpv6Address(addr.getAddress()); } int res = sendTo(fd, buf, pos, limit, address, scopeId, port); if (res >= 0) { return res; } if (res == ERROR_ECONNREFUSED_NEGATIVE) { throw new PortUnreachableException("sendTo failed"); } return ioResult("sendTo", res, SEND_TO_CONNECTION_RESET_EXCEPTION, SEND_TO_CLOSED_CHANNEL_EXCEPTION); }
public final int sendToAddresses(long memoryAddress, int length, InetAddress addr, int port) throws IOException { // just duplicate the toNativeInetAddress code here to minimize object creation as this method is expected // to be called frequently byte[] address; int scopeId; if (addr instanceof Inet6Address) { address = addr.getAddress(); scopeId = ((Inet6Address) addr).getScopeId(); } else { // convert to ipv4 mapped ipv6 address; scopeId = 0; address = ipv4MappedIpv6Address(addr.getAddress()); } int res = sendToAddresses(fd, memoryAddress, length, address, scopeId, port); if (res >= 0) { return res; } if (res == ERROR_ECONNREFUSED_NEGATIVE) { throw new PortUnreachableException("sendToAddresses failed"); } return ioResult("sendToAddresses", res, CONNECTION_RESET_EXCEPTION_SENDMSG, SEND_TO_ADDRESSES_CLOSED_CHANNEL_EXCEPTION); }
public final int sendToAddress(long memoryAddress, int pos, int limit, InetAddress addr, int port) throws IOException { // just duplicate the toNativeInetAddress code here to minimize object creation as this method is expected // to be called frequently byte[] address; int scopeId; if (addr instanceof Inet6Address) { address = addr.getAddress(); scopeId = ((Inet6Address) addr).getScopeId(); } else { // convert to ipv4 mapped ipv6 address; scopeId = 0; address = ipv4MappedIpv6Address(addr.getAddress()); } int res = sendToAddress(fd, memoryAddress, pos, limit, address, scopeId, port); if (res >= 0) { return res; } if (res == ERROR_ECONNREFUSED_NEGATIVE) { throw new PortUnreachableException("sendToAddress failed"); } return ioResult("sendToAddress", res, SEND_TO_ADDRESS_CONNECTION_RESET_EXCEPTION, SEND_TO_ADDRESS_CLOSED_CHANNEL_EXCEPTION); }
public final int sendTo(ByteBuffer buf, int pos, int limit, InetAddress addr, int port) throws IOException { // just duplicate the toNativeInetAddress code here to minimize object creation as this method is expected // to be called frequently byte[] address; int scopeId; if (addr instanceof Inet6Address) { address = addr.getAddress(); scopeId = ((Inet6Address) addr).getScopeId(); } else { // convert to ipv4 mapped ipv6 address; scopeId = 0; address = ipv4MappedIpv6Address(addr.getAddress()); } int res = sendTo(fd, buf, pos, limit, address, scopeId, port); if (res >= 0) { return res; } if (res == ERROR_ECONNREFUSED_NEGATIVE) { throw new PortUnreachableException("sendTo failed"); } return ioResult("sendTo", res, SEND_TO_CONNECTION_RESET_EXCEPTION, SEND_TO_CLOSED_CHANNEL_EXCEPTION); }
public final int sendToAddresses(long memoryAddress, int length, InetAddress addr, int port) throws IOException { // just duplicate the toNativeInetAddress code here to minimize object creation as this method is expected // to be called frequently byte[] address; int scopeId; if (addr instanceof Inet6Address) { address = addr.getAddress(); scopeId = ((Inet6Address) addr).getScopeId(); } else { // convert to ipv4 mapped ipv6 address; scopeId = 0; address = ipv4MappedIpv6Address(addr.getAddress()); } int res = sendToAddresses(fd, memoryAddress, length, address, scopeId, port); if (res >= 0) { return res; } if (res == ERROR_ECONNREFUSED_NEGATIVE) { throw new PortUnreachableException("sendToAddresses failed"); } return ioResult("sendToAddresses", res, CONNECTION_RESET_EXCEPTION_SENDMSG, SEND_TO_ADDRESSES_CLOSED_CHANNEL_EXCEPTION); }
public final int sendToAddress(long memoryAddress, int pos, int limit, InetAddress addr, int port) throws IOException { // just duplicate the toNativeInetAddress code here to minimize object creation as this method is expected // to be called frequently byte[] address; int scopeId; if (addr instanceof Inet6Address) { address = addr.getAddress(); scopeId = ((Inet6Address) addr).getScopeId(); } else { // convert to ipv4 mapped ipv6 address; scopeId = 0; address = ipv4MappedIpv6Address(addr.getAddress()); } int res = sendToAddress(fd, memoryAddress, pos, limit, address, scopeId, port); if (res >= 0) { return res; } if (res == ERROR_ECONNREFUSED_NEGATIVE) { throw new PortUnreachableException("sendToAddress failed"); } return ioResult("sendToAddress", res, SEND_TO_ADDRESS_CONNECTION_RESET_EXCEPTION, SEND_TO_ADDRESS_CLOSED_CHANNEL_EXCEPTION); }
private static int maybeThrowAfterRecvfrom(boolean isRead, boolean isConnected, ErrnoException errnoException) throws SocketException, SocketTimeoutException { if (isRead) { if (errnoException.errno == EAGAIN) { return 0; } else { throw errnoException.rethrowAsSocketException(); } } else { if (isConnected && errnoException.errno == ECONNREFUSED) { throw new PortUnreachableException("", errnoException); } else if (errnoException.errno == EAGAIN) { throw new SocketTimeoutException(errnoException); } else { throw errnoException.rethrowAsSocketException(); } } }
private static int maybeThrowAfterRecvfrom(boolean isRead, boolean isConnected, ErrnoException errnoException) throws SocketException, SocketTimeoutException { if (isRead) { if (errnoException.errno == EAGAIN) { return 0; } else { throw errnoException.rethrowAsSocketException(); } } else { if (isConnected && errnoException.errno == ECONNREFUSED) { throw new PortUnreachableException("", errnoException); } else if (errnoException.errno == EAGAIN) { throw new SocketTimeoutException(errnoException); } else { throw errnoException.rethrowAsSocketException(); } } }
throw( new PortUnreachableException());
private static int maybeThrowAfterRecvfrom(boolean isRead, boolean isConnected, ErrnoException errnoException) throws SocketException, SocketTimeoutException { if (isRead) { if (errnoException.errno == EAGAIN) { return 0; } else { throw errnoException.rethrowAsSocketException(); } } else { if (isConnected && errnoException.errno == ECONNREFUSED) { throw new PortUnreachableException("", errnoException); } else if (errnoException.errno == EAGAIN) { throw new SocketTimeoutException(errnoException); } else { throw errnoException.rethrowAsSocketException(); } } }
private static int maybeThrowAfterRecvfrom(boolean isRead, boolean isConnected, ErrnoException errnoException) throws SocketException, SocketTimeoutException { if (isRead) { if (errnoException.errno == EAGAIN) { return 0; } else { throw errnoException.rethrowAsSocketException(); } } else { if (isConnected && errnoException.errno == ECONNREFUSED) { throw new PortUnreachableException("", errnoException); } else if (errnoException.errno == EAGAIN) { throw new SocketTimeoutException(errnoException); } else { throw errnoException.rethrowAsSocketException(); } } }
private static int maybeThrowAfterRecvfrom(boolean isRead, boolean isConnected, ErrnoException errnoException) throws SocketException, SocketTimeoutException { if (isRead) { if (errnoException.errno == EAGAIN) { return 0; } else { throw errnoException.rethrowAsSocketException(); } } else { if (isConnected && errnoException.errno == ECONNREFUSED) { throw new PortUnreachableException("", errnoException); } else if (errnoException.errno == EAGAIN) { throw new SocketTimeoutException(errnoException); } else { throw errnoException.rethrowAsSocketException(); } } }
private static int maybeThrowAfterRecvfrom(boolean isRead, boolean isConnected, ErrnoException errnoException) throws SocketException, SocketTimeoutException { if (isRead) { if (errnoException.errno == EAGAIN) { return 0; } else { throw errnoException.rethrowAsSocketException(); } } else { if (isConnected && errnoException.errno == ECONNREFUSED) { throw new PortUnreachableException("", errnoException); } else if (errnoException.errno == EAGAIN) { throw new SocketTimeoutException(errnoException); } else { throw errnoException.rethrowAsSocketException(); } } }
public final int sendTo(ByteBuffer buf, int pos, int limit, InetAddress addr, int port) throws IOException { // just duplicate the toNativeInetAddress code here to minimize object creation as this method is expected // to be called frequently byte[] address; int scopeId; if (addr instanceof Inet6Address) { address = addr.getAddress(); scopeId = ((Inet6Address) addr).getScopeId(); } else { // convert to ipv4 mapped ipv6 address; scopeId = 0; address = ipv4MappedIpv6Address(addr.getAddress()); } int res = sendTo(fd, buf, pos, limit, address, scopeId, port); if (res >= 0) { return res; } if (res == ERROR_ECONNREFUSED_NEGATIVE) { throw new PortUnreachableException("sendTo failed"); } return ioResult("sendTo", res, SEND_TO_CONNECTION_RESET_EXCEPTION, SEND_TO_CLOSED_CHANNEL_EXCEPTION); }
public final int sendTo(ByteBuffer buf, int pos, int limit, InetAddress addr, int port) throws IOException { // just duplicate the toNativeInetAddress code here to minimize object creation as this method is expected // to be called frequently byte[] address; int scopeId; if (addr instanceof Inet6Address) { address = addr.getAddress(); scopeId = ((Inet6Address) addr).getScopeId(); } else { // convert to ipv4 mapped ipv6 address; scopeId = 0; address = ipv4MappedIpv6Address(addr.getAddress()); } int res = sendTo(fd, buf, pos, limit, address, scopeId, port); if (res >= 0) { return res; } if (res == ERROR_ECONNREFUSED_NEGATIVE) { throw new PortUnreachableException("sendTo failed"); } return ioResult("sendTo", res, SEND_TO_CONNECTION_RESET_EXCEPTION, SEND_TO_CLOSED_CHANNEL_EXCEPTION); }