java.lang.Object
java.net.DatagramSocket
org.newsclub.net.unix.AFDatagramSocket<AFUNIXSocketAddress>
org.newsclub.net.unix.AFUNIXDatagramSocket
- All Implemented Interfaces:
Closeable,AutoCloseable,AFSocketExtensions,AFSomeSocket,AFUNIXSocketExtensions,FileDescriptorAccess
public final class AFUNIXDatagramSocket
extends AFDatagramSocket<AFUNIXSocketAddress>
implements AFUNIXSocketExtensions
A
DatagramSocket implementation that works with AF_UNIX Unix domain sockets.- Author:
- Christian Kohlschütter
-
Nested Class Summary
Nested classes/interfaces inherited from class org.newsclub.net.unix.AFDatagramSocket
AFDatagramSocket.Constructor<A extends AFSocketAddress> -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the queue of incomingFileDescriptors that were sent as ancillary messages.Retrieves the "peer credentials" for this connection.Retrieves an array of incomingFileDescriptors that were sent as ancillary messages, along with a call toInputStream.read(), etc.booleanReturnstrueif there are pending file descriptors to be sent as part of an ancillary message.protected AFUNIXDatagramChannelCreates a newDatagramChannelthat is associated with this socket.static AFUNIXDatagramSocketReturns a newAFUNIXDatagramSocketinstance.voidsetOutboundFileDescriptors(FileDescriptor... fdescs) Sets a list ofFileDescriptors that should be sent as an ancillary message along with the next write.Methods inherited from class org.newsclub.net.unix.AFDatagramSocket
addressFamily, bind, close, connect, connect, ensureAncillaryReceiveBufferSize, getAncillaryDataSupport, getAncillaryReceiveBufferSize, getFileDescriptor, getImplExtensions, getLocalSocketAddress, getRemoteSocketAddress, isBound, isClosed, isConnected, isDeleteOnClose, newInstance, newInstance, peek, receive, send, setAncillaryReceiveBufferSize, setDeleteOnClose, socketAddressClassMethods inherited from class java.net.DatagramSocket
disconnect, getBroadcast, getInetAddress, getLocalAddress, getLocalPort, getOption, getPort, getReceiveBufferSize, getReuseAddress, getSendBufferSize, getSoTimeout, getTrafficClass, joinGroup, leaveGroup, setBroadcast, setDatagramSocketImplFactory, setOption, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setSoTimeout, setTrafficClass, supportedOptionsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.newsclub.net.unix.AFSocketExtensions
ensureAncillaryReceiveBufferSize, getAncillaryReceiveBufferSize, setAncillaryReceiveBufferSize
-
Method Details
-
newChannel
Description copied from class:AFDatagramSocketCreates a newDatagramChannelthat is associated with this socket.- Specified by:
newChannelin classAFDatagramSocket<AFUNIXSocketAddress>- Returns:
- The channel.
-
newInstance
Returns a newAFUNIXDatagramSocketinstance.- Returns:
- The new instance.
- Throws:
IOException- on error.
-
getChannel
- Overrides:
getChannelin classAFDatagramSocket<AFUNIXSocketAddress>
-
getReceivedFileDescriptors
Description copied from interface:AFUNIXSocketExtensionsRetrieves an array of incomingFileDescriptors that were sent as ancillary messages, along with a call toInputStream.read(), etc. NOTE: Another call to this method will not return the same file descriptors again (most likely, an empty array will be returned).- Specified by:
getReceivedFileDescriptorsin interfaceAFUNIXSocketExtensions- Returns:
- The file descriptors, or an empty array if none were available.
- Throws:
IOException- if the operation fails.
-
clearReceivedFileDescriptors
public void clearReceivedFileDescriptors()Description copied from interface:AFUNIXSocketExtensionsClears the queue of incomingFileDescriptors that were sent as ancillary messages.- Specified by:
clearReceivedFileDescriptorsin interfaceAFUNIXSocketExtensions
-
setOutboundFileDescriptors
Description copied from interface:AFUNIXSocketExtensionsSets a list ofFileDescriptors that should be sent as an ancillary message along with the next write. Important: There can only be one set of file descriptors active until the write completes. The socket also needs to be connected for this operation to succeed. It is also important to know that there may be an upper limit imposed by the operation system as to how many file descriptors can be sent at once. Linux, for example, may support up to 253. If the number of file descriptors exceeds the limit, an exception may be thrown when sending data along with the ancillary message containing the file descriptors.- Specified by:
setOutboundFileDescriptorsin interfaceAFUNIXSocketExtensions- Parameters:
fdescs- The file descriptors, ornullif none.- Throws:
IOException- if the operation fails.
-
hasOutboundFileDescriptors
public boolean hasOutboundFileDescriptors()Description copied from interface:AFUNIXSocketExtensionsReturnstrueif there are pending file descriptors to be sent as part of an ancillary message.- Specified by:
hasOutboundFileDescriptorsin interfaceAFUNIXSocketExtensions- Returns:
trueif there are file descriptors pending.
-
getPeerCredentials
Description copied from interface:AFUNIXSocketExtensionsRetrieves the "peer credentials" for this connection. These credentials may be useful to authenticate the other end of the socket (client or server). Depending on the socket/connection/environment, you may not receive any or all credentials. For example, on Linux,AFUNIXDatagramSocketandAFUNIXDatagramChannelmay not be able to retrieve credentials at all.- Specified by:
getPeerCredentialsin interfaceAFUNIXSocketExtensions- Returns:
- The peer's credentials, or
nullif they couldn't be retrieved. - Throws:
IOException- If there was an error returning these credentials.
-