@Override public boolean isConnected() { if (null == chan) { return false; } return chan.isConnected(); }
public final UnixSocketAddress getRemoteSocketAddress() { if (!isConnected()) { return null; } return remoteAddress != null ? remoteAddress : (remoteAddress = Common.getpeername(getFD())); }
/** * Retrieves the credentials for this UNIX socket. Clients calling this * method will receive the server's credentials, and servers will receive * the client's credentials. User ID, group ID, and PID are supplied. * * See man unix 7; SCM_CREDENTIALS * * @throws UnsupportedOperationException if the underlying socket library * doesn't support the SO_PEERCRED option * @throws SocketException if fetching the socket option failed. * * @return the credentials of the remote; null if not connected */ public final Credentials getCredentials() throws SocketException { if (!chan.isConnected()) { return null; } try { return chan.getOption(UnixSocketOptions.SO_PEERCRED); } catch (IOException e) { throw (SocketException)new SocketException().initCause(e); } }
@Override public int send(ByteBuffer src, SocketAddress target) throws IOException { UnixSocketAddress remote = null; if (null == target) { if (isConnected()) { remote = remoteAddress; } else { throw new IllegalArgumentException("Destination address cannot be null on unconnected datagram sockets"); } } else { if (!(target instanceof UnixSocketAddress)) { throw new UnsupportedAddressTypeException(); } remote = (UnixSocketAddress)target; } SockAddrUnix sa = (null == remote) ? null : remote.getStruct(); int addrlen = (null == sa) ? 0 : sa.length(); int n = Native.sendto(getFD(), src, sa, addrlen); if (n < 0) { throw new IOException(Native.getLastErrorString()); } return n; }