@Override public void connect(SocketAddress endpoint, int timeout) throws IOException { if (timeout < 0) { throw new IllegalArgumentException("Timeout may not be negative: " + timeout); } if (!(endpoint instanceof UnixSocketAddress)) { throw new IllegalArgumentException("Unsupported address type: " + endpoint.getClass().getName()); } synchronized (connectLock) { channel.connect((UnixSocketAddress) endpoint); } }
/** * Check whether we can connect to a local Unix socket * */ public static boolean canConnectUnixSocket(File path) { try (UnixSocketChannel channel = UnixSocketChannel.open()) { return channel.connect(new UnixSocketAddress(path)); } catch (IOException e) { return false; } } }
public void connect(SocketAddress addr, Integer timeout) throws IOException { if (addr instanceof UnixSocketAddress) { chan.connect((UnixSocketAddress) addr); } else { throw new IllegalArgumentException("address of type " + addr.getClass() + " are not supported. Use " + UnixSocketAddress.class + " instead"); } }
public static final UnixSocketChannel open(UnixSocketAddress remote) throws IOException { UnixSocketChannel channel = new UnixSocketChannel(); channel.connect(remote); return channel; }
@Override public boolean connect(SocketAddress remote) throws IOException { if (remote instanceof UnixSocketAddress) { return connect(((UnixSocketAddress) remote)); } else { throw new UnsupportedAddressTypeException(); } }
@Override public void connect(SocketAddress endpoint, int timeout) throws IOException { if (endpoint == null) { throw new NullPointerException(); } if (timeout < 0) { throw new IllegalArgumentException("Timeout may not be negative: " + timeout); } if (!(endpoint instanceof UnixSocketAddress)) { throw new IllegalArgumentException("Unsupported address type: " + endpoint.getClass().getName()); } synchronized (connectLock) { channel.connect((UnixSocketAddress) endpoint); } }
public static final UnixSocketChannel open(UnixSocketAddress remote) throws IOException { UnixSocketChannel channel = new UnixSocketChannel(); try { channel.connect(remote); } catch (IOException e) { channel.close(); throw e; } return channel; }
protected void init_unixsock(Ruby runtime, IRubyObject _path, boolean server) { ByteList path = _path.convertToString().getByteList(); String fpath = Helpers.decodeByteList(runtime, path); int maxSize = 103; // Max size from Darwin, lowest common value we know of if (fpath.length() > 103) { throw runtime.newArgumentError("too long unix socket path (max: " + maxSize + "bytes)"); } try { if (server) { UnixServerSocketChannel channel = UnixServerSocketChannel.open(); UnixServerSocket socket = channel.socket(); // TODO: listen backlog socket.bind(new UnixSocketAddress(new File(fpath))); init_sock(runtime, channel, fpath); } else { File fpathFile = new File(fpath); if (!fpathFile.exists()) { throw runtime.newErrnoENOENTError("unix socket"); } UnixSocketChannel channel = UnixSocketChannel.open(); channel.connect(new UnixSocketAddress(fpathFile)); init_sock(runtime, channel); } } catch (IOException ioe) { throw runtime.newIOErrorFromException(ioe); } }
protected void init_unixsock(Ruby runtime, IRubyObject _path, boolean server) { ByteList path = _path.convertToString().getByteList(); String fpath = Helpers.decodeByteList(runtime, path); int maxSize = 103; // Max size from Darwin, lowest common value we know of if (fpath.length() > 103) { throw runtime.newArgumentError("too long unix socket path (max: " + maxSize + "bytes)"); } try { if (server) { UnixServerSocketChannel channel = UnixServerSocketChannel.open(); UnixServerSocket socket = channel.socket(); // TODO: listen backlog socket.bind(new UnixSocketAddress(new File(fpath))); init_sock(runtime, channel, fpath); } else { File fpathFile = new File(fpath); if (!fpathFile.exists()) { throw runtime.newErrnoENOENTError("unix socket"); } UnixSocketChannel channel = UnixSocketChannel.open(); channel.connect(new UnixSocketAddress(fpathFile)); init_sock(runtime, channel); } } catch (IOException ioe) { throw runtime.newIOErrorFromException(ioe); } }
channel.connect(new UnixSocketAddress(fpathFile));
channel.connect(new UnixSocketAddress(fpathFile));
result = ((UnixSocketChannel) channel).connect((UnixSocketAddress) addr);
((UnixSocketChannel)channel).connect((UnixSocketAddress)addr);
((UnixSocketChannel)channel).connect((UnixSocketAddress)addr);
result = ((UnixSocketChannel) channel).connect((UnixSocketAddress) addr);