@Override public UnixDatagramSocket socket() { try { return new UnixDatagramSocket(this); } catch (SocketException e) { throw new NullPointerException("Could not create UnixDatagramSocket"); } }
/** * Binds this UnixDatagramSocket to a specific AF_UNIX address. * <p> * If the address is {@code null}, then on Linux, an autobind will be performed, * which will bind this socket in Linux' abstract namespace on a unique path, chosen by * the system. On all other platforms, A temporary path in the regular filesystem will be chosen. *<p> * @param local The {@link UnixSocketAddress} to bind to. * @throws SocketException if any error happens during the bind, or if the * socket is already bound. * @throws UnsupportedAddressTypeException if addr is a SocketAddress subclass * not supported by this socket. */ @Override public void bind(final SocketAddress local) throws SocketException { if (null != chan) { if (isClosed()) { throw new SocketException("Socket is closed"); } if (isBound()) { throw new SocketException("already bound"); } try { chan.bind(local); } catch (IOException e) { throw (SocketException)new SocketException().initCause(e); } } }
@Override public synchronized void close() { if (null != chan && closed.compareAndSet(false, true)) { try { chan.close(); } catch (IOException e) { ignore(); } } }
/** * Returns the address of the endpoint this socket is connected to, or * {@code null} if it is unconnected. * * @return a {@code SocketAddress} representing the remote * endpoint of this socket, or {@code null} if it is * not connected. * A non-null return value is always of type {@link UnixSocketAddress} */ @Override public SocketAddress getRemoteSocketAddress() { if (!isConnected()) { return null; } return chan.getRemoteSocketAddress(); }
/** * Returns the address of the endpoint this socket is bound to. * * @return a {@code SocketAddress} representing the local endpoint of this * socket, or {@code null} if it is closed or not bound. * A non-null return value is always of type {@link UnixSocketAddress} * @see #bind(SocketAddress) */ @Override public SocketAddress getLocalSocketAddress() { if (isClosed()) { return null; } if (null == chan) { return null; } return chan.getLocalSocketAddress(); }