@Override public UnixDatagramChannel bind(SocketAddress local) throws IOException { localAddress = bindHandler.bind(getFD(), local); return this; }
public final UnixSocketAddress getLocalSocketAddress() { return localAddress != null ? localAddress : (localAddress = Common.getsockname(getFD())); }
@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; }
@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 getRemoteSocketAddress() { if (!isConnected()) { return null; } return remoteAddress != null ? remoteAddress : (remoteAddress = Common.getpeername(getFD())); }
@Override public UnixSocketAddress receive(ByteBuffer src) throws IOException { UnixSocketAddress remote = new UnixSocketAddress(); int n = Native.recvfrom(getFD(), src, remote.getStruct()); if (n < 0) { throw new IOException(Native.getLastErrorString()); } return remote; }
@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; }