synchronized UnixSocketAddress bind(int fd, SocketAddress local) throws IOException { if (null != local && !(local instanceof UnixSocketAddress)) { throw new UnsupportedAddressTypeException(); } if (bound.get()) { throw new AlreadyBoundException(); } else { UnixSocketAddress ret = Common.bind(fd, (UnixSocketAddress)local); bound.set(true); return ret; } }
@Override public <T> T getOption(SocketOption<T> name) throws IOException { if (!supportedOptions().contains(name)) { throw new UnsupportedOperationException("'" + name + "' not supported"); } return Common.getSocketOption(getFD(), name); }
public final UnixSocketAddress getLocalSocketAddress() { if (localAddress != null) { return localAddress; } else { localAddress = Common.getsockname(getFD()); return localAddress; } }
@Override public <T> DatagramChannel setOption(SocketOption<T> name, T value) throws IOException { if (name == null) { throw new IllegalArgumentException("name may not be null"); } if (!supportedOptions().contains(name)) { throw new UnsupportedOperationException("'" + name + "' not supported"); } Common.setSocketOption(getFD(), name, value); return this; }
public final UnixSocketAddress getRemoteSocketAddress() { if (!isConnected()) { return null; } if (remoteAddress != null) { return remoteAddress; } else { remoteAddress = Common.getpeername(getFD()); return remoteAddress; } }
@Override public <T> SocketChannel setOption(SocketOption<T> name, T value) throws IOException { if (name == null) { throw new IllegalArgumentException("name may not be null"); } if (!supportedOptions().contains(name)) { throw new UnsupportedOperationException("'" + name + "' not supported"); } Common.setSocketOption(getFD(), name, value); return this; }
public final UnixSocketAddress getRemoteSocketAddress() { if (!isConnected()) { return null; } return remoteAddress != null ? remoteAddress : (remoteAddress = Common.getpeername(getFD())); }
public final UnixSocketAddress getLocalSocketAddress() { return localAddress != null ? localAddress : (localAddress = Common.getsockname(getFD())); }
public void bind(SocketAddress endpoint, int backlog) throws IOException { if (null != endpoint && !(endpoint instanceof UnixSocketAddress)) { throw new UnsupportedAddressTypeException(); } localAddress = Common.bind(fd, (UnixSocketAddress)endpoint); if (Native.listen(fd, backlog) < 0) { throw new IOException(Native.getLastErrorString()); } }
@Override public <T> T getOption(SocketOption<T> name) throws IOException { if (!supportedOptions().contains(name)) { throw new UnsupportedOperationException("'" + name + "' not supported"); } return Common.getSocketOption(getFD(), name); }
static UnixSocketAddress bind(int fd, UnixSocketAddress local) throws IOException { SockAddrUnix sa; if (null == local) { // Support autobind sa = SockAddrUnix.create(); sa.setFamily(ProtocolFamily.PF_UNIX); if (currentOS == OS.LINUX) { // On Linux, we simply set an empty path sa.setPath(""); } else { // Emulate something similar (bind to some random unique address), // but use regular namespace File f = Files.createTempFile("jnr-unixsocket-tmp", ".sock").toFile(); f.deleteOnExit(); f.delete(); sa.setPath(f.getPath()); } } else { sa = local.getStruct(); } if (Native.bind(fd, sa, sa.length()) < 0) { throw new IOException(Native.getLastErrorString()); } return getsockname(fd); }