Module org.newsclub.net.unix
Package org.newsclub.net.unix
Class AFDatagramSocket<A extends AFSocketAddress>
java.lang.Object
java.net.DatagramSocket
org.newsclub.net.unix.AFDatagramSocket<A>
- Type Parameters:
A- The concreteAFSocketAddressthat is supported by this type.
- All Implemented Interfaces:
Closeable,AutoCloseable,AFSocketExtensions,AFSomeSocket,FileDescriptorAccess
- Direct Known Subclasses:
AFUNIXDatagramSocket
public abstract class AFDatagramSocket<A extends AFSocketAddress>
extends DatagramSocket
implements AFSomeSocket, AFSocketExtensions
A
DatagramSocket implementation that works with junixsocket.- Author:
- Christian Kohlschütter
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAFDatagramSocket.Constructor<A extends AFSocketAddress>A reference to the constructor of anAFDatagramSocketsubclass. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final AFAddressFamily<A>Returns the address family supported by this implementation.final voidbind(SocketAddress addr) final voidclose()final voidconnect(InetAddress address, int port) final voidconnect(SocketAddress addr) final voidensureAncillaryReceiveBufferSize(int minSize) Ensures a minimum ancillary receive buffer size.protected final org.newsclub.net.unix.AncillaryDataSupportReturns theAncillaryDataSupportinstance.final intReturns the size of the receive buffer for ancillary messages (in bytes).final FileDescriptorReturns the correspondingFileDescriptor.protected AFSocketImplExtensions<A>Returns the internal helper instance for address-specific extensions.final @Nullable AReturns the socket's local socket address, ornullif unavailable or if there was a problem retrieving it.final @Nullable AReturns the socket's remote socket address, ornullif unavailable/not connected, or if there was a problem retrieving it.final booleanisBound()final booleanisClosed()final booleanfinal booleanChecks if thisAFDatagramSocket's bound filename should be removed uponclose().protected abstract AFDatagramChannel<A>Creates a newDatagramChannelthat is associated with this socket.protected static final <A extends AFSocketAddress>
AFDatagramSocket<A>newInstance(AFDatagramSocket.Constructor<A> constructor) Returns a newAFDatagramSocketinstance.protected static final <A extends AFSocketAddress>
AFDatagramSocket<A>newInstance(AFDatagramSocket.Constructor<A> constructor, FileDescriptor fdObj, int localPort, int remotePort) Creates a newAFDatagramSocket.final voidReads the next received packet without actually removing it from the queue.final voidfinal voidfinal voidsetAncillaryReceiveBufferSize(int size) Sets the size of the receive buffer for ancillary messages (in bytes).final voidsetDeleteOnClose(boolean b) Enables/disables deleting thisAFDatagramSocket's bound filename uponclose().protected final Class<? extends AFSocketAddress>Returns theAFSocketAddresstype supported by this socket.Methods 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, supportedOptions
-
Constructor Details
-
AFDatagramSocket
Creates a newAFDatagramSocketinstance.- Parameters:
impl- The correspondingSocketImplclass.- Throws:
IOException- on error.
-
-
Method Details
-
newChannel
Creates a newDatagramChannelthat is associated with this socket.- Returns:
- The channel.
-
getAncillaryDataSupport
protected final org.newsclub.net.unix.AncillaryDataSupport getAncillaryDataSupport()Returns theAncillaryDataSupportinstance.- Returns:
- The instance.
-
socketAddressClass
Returns theAFSocketAddresstype supported by this socket.- Returns:
- The supported
AFSocketAddress.
-
newInstance
protected static final <A extends AFSocketAddress> AFDatagramSocket<A> newInstance(AFDatagramSocket.Constructor<A> constructor) throws IOException Returns a newAFDatagramSocketinstance.- Type Parameters:
A- The concreteAFSocketAddressthat is supported by this type.- Parameters:
constructor- The supplying constructor.- Returns:
- The new instance.
- Throws:
IOException- on error.
-
newInstance
protected static final <A extends AFSocketAddress> AFDatagramSocket<A> newInstance(AFDatagramSocket.Constructor<A> constructor, FileDescriptor fdObj, int localPort, int remotePort) throws IOException Creates a newAFDatagramSocket.- Type Parameters:
A- The concreteAFSocketAddressthat is supported by this type.- Parameters:
constructor- The supplying constructor.fdObj- The file descriptor.localPort- The local port.remotePort- The remote port.- Returns:
- The new instance.
- Throws:
IOException- on error.
-
connect
- Overrides:
connectin classDatagramSocket
-
peek
Reads the next received packet without actually removing it from the queue. In other words, once a packet is received, calling this method multiple times in a row will not have further effects on the packet contents. This call still blocks until at least one packet has been received and added to the queue.- Parameters:
p- The packet.- Throws:
IOException- on error.
-
send
- Overrides:
sendin classDatagramSocket- Throws:
IOException
-
connect
- Overrides:
connectin classDatagramSocket- Throws:
SocketException
-
getRemoteSocketAddress
Description copied from interface:AFSomeSocketReturns the socket's remote socket address, ornullif unavailable/not connected, or if there was a problem retrieving it.- Specified by:
getRemoteSocketAddressin interfaceAFSomeSocket- Overrides:
getRemoteSocketAddressin classDatagramSocket- Returns:
- The remote socket address, or
null.
-
isConnected
public final boolean isConnected()- Overrides:
isConnectedin classDatagramSocket
-
isBound
public final boolean isBound()- Overrides:
isBoundin classDatagramSocket
-
close
public final void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classDatagramSocket
-
bind
- Overrides:
bindin classDatagramSocket- Throws:
SocketException
-
getLocalSocketAddress
Description copied from interface:AFSomeSocketReturns the socket's local socket address, ornullif unavailable or if there was a problem retrieving it.- Specified by:
getLocalSocketAddressin interfaceAFSomeSocket- Overrides:
getLocalSocketAddressin classDatagramSocket- Returns:
- The local socket address, or
null.
-
isDeleteOnClose
public final boolean isDeleteOnClose()Checks if thisAFDatagramSocket's bound filename should be removed uponclose(). Deletion is not guaranteed, especially when not supported (e.g., addresses in the abstract namespace).- Returns:
trueif an attempt is made to delete the socket file uponclose().
-
setDeleteOnClose
public final void setDeleteOnClose(boolean b) Enables/disables deleting thisAFDatagramSocket's bound filename uponclose(). Deletion is not guaranteed, especially when not supported (e.g., addresses in the abstract namespace).- Parameters:
b- Enabled iftrue.
-
getAncillaryReceiveBufferSize
public final int getAncillaryReceiveBufferSize()Description copied from interface:AFSocketExtensionsReturns the size of the receive buffer for ancillary messages (in bytes).- Specified by:
getAncillaryReceiveBufferSizein interfaceAFSocketExtensions- Returns:
- The size.
-
setAncillaryReceiveBufferSize
public final void setAncillaryReceiveBufferSize(int size) Description copied from interface:AFSocketExtensionsSets the size of the receive buffer for ancillary messages (in bytes). To disable handling ancillary messages, set it to 0 (default).- Specified by:
setAncillaryReceiveBufferSizein interfaceAFSocketExtensions- Parameters:
size- The size.
-
ensureAncillaryReceiveBufferSize
public final void ensureAncillaryReceiveBufferSize(int minSize) Description copied from interface:AFSocketExtensionsEnsures a minimum ancillary receive buffer size.- Specified by:
ensureAncillaryReceiveBufferSizein interfaceAFSocketExtensions- Parameters:
minSize- The minimum size (in bytes).
-
isClosed
public final boolean isClosed()- Overrides:
isClosedin classDatagramSocket
-
getChannel
- Overrides:
getChannelin classDatagramSocket
-
getFileDescriptor
Description copied from interface:FileDescriptorAccessReturns the correspondingFileDescriptor.- Specified by:
getFileDescriptorin interfaceFileDescriptorAccess- Returns:
- The corresponding
FileDescriptor. - Throws:
IOException- on error.
-
receive
- Overrides:
receivein classDatagramSocket- Throws:
IOException
-
addressFamily
Returns the address family supported by this implementation.- Returns:
- The family.
-
getImplExtensions
Returns the internal helper instance for address-specific extensions.- Returns:
- The helper instance.
- Throws:
UnsupportedOperationException- if such extensions are not supported for this address type.
-