Module org.newsclub.net.unix
Package org.newsclub.net.unix
Class AFDatagramChannel<A extends AFSocketAddress>
java.lang.Object
java.nio.channels.spi.AbstractInterruptibleChannel
java.nio.channels.SelectableChannel
java.nio.channels.spi.AbstractSelectableChannel
java.nio.channels.DatagramChannel
org.newsclub.net.unix.AFDatagramChannel<A>
- Type Parameters:
A
- The supported address type.
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ByteChannel
,Channel
,GatheringByteChannel
,InterruptibleChannel
,MulticastChannel
,NetworkChannel
,ReadableByteChannel
,ScatteringByteChannel
,WritableByteChannel
,AFSocketExtensions
,AFSomeSocket
,AFSomeSocketChannel
,AFSomeSocketThing
,FileDescriptorAccess
- Direct Known Subclasses:
AFSYSTEMDatagramChannel
,AFTIPCDatagramChannel
,AFUNIXDatagramChannel
,AFVSOCKDatagramChannel
public abstract class AFDatagramChannel<A extends AFSocketAddress>
extends DatagramChannel
implements AFSomeSocket, AFSocketExtensions, AFSomeSocketChannel
A
DatagramChannel
implementation that works with junixsocket.- Author:
- Christian Kohlschütter
-
Constructor Summary
ModifierConstructorDescriptionprotected
AFDatagramChannel
(AFSelectorProvider<A> selectorProvider, AFDatagramSocket<A> socket) Creates a newAFDatagramChannel
instance. -
Method Summary
Modifier and TypeMethodDescriptionfinal AFDatagramChannel
<A> bind
(SocketAddress local) final AFDatagramChannel
<A> connect
(SocketAddress remote) final AFDatagramChannel
<A> final void
ensureAncillaryReceiveBufferSize
(int minSize) Ensures a minimum ancillary receive buffer size.protected final AFDatagramSocket
<A> Returns the correspondingSocket
.final int
Returns the size of the receive buffer for ancillary messages (in bytes).final FileDescriptor
Returns the correspondingFileDescriptor
.final @Nullable A
final @Nullable A
Returns the socket's local socket address, ornull
if unavailable or if there was a problem retrieving it.final <T> T
getOption
(SocketOption<T> name) final @Nullable A
final @Nullable A
Returns the socket's remote socket address, ornull
if unavailable/not connected, or if there was a problem retrieving it.protected final void
protected final void
implConfigureBlocking
(boolean block) final boolean
isBound()
Returns the binding state of the socket.final boolean
final boolean
Checks if thisDatagramSocket
's bound filename should be removed uponAbstractInterruptibleChannel.close()
.final MembershipKey
join
(InetAddress group, NetworkInterface interf) final MembershipKey
join
(InetAddress group, NetworkInterface interf, InetAddress source) static DatagramChannel
open
(ProtocolFamily family) Opens a datagram channel.final int
read
(ByteBuffer dst) final long
read
(ByteBuffer[] dsts, int offset, int length) final A
receive
(ByteBuffer dst) final int
send
(ByteBuffer src, SocketAddress target) final void
setAncillaryReceiveBufferSize
(int size) Sets the size of the receive buffer for ancillary messages (in bytes).final void
setDeleteOnClose
(boolean b) Enables/disables deleting thisDatagramSocket
's bound filename uponAbstractInterruptibleChannel.close()
.final <T> AFDatagramChannel
<A> setOption
(SocketOption<T> name, T value) void
setShutdownOnClose
(boolean enabled) Configures whether the socket should be shutdown uponCloseable.close()
, which is the default.final AFDatagramSocket
<A> socket()
final Set
<SocketOption<?>> final int
write
(ByteBuffer src) final long
write
(ByteBuffer[] srcs, int offset, int length) Methods inherited from class java.nio.channels.DatagramChannel
open, read, validOps, write
Methods inherited from class java.nio.channels.spi.AbstractSelectableChannel
blockingLock, configureBlocking, implCloseChannel, isBlocking, isRegistered, keyFor, provider, register
Methods inherited from class java.nio.channels.SelectableChannel
register
Methods inherited from class java.nio.channels.spi.AbstractInterruptibleChannel
begin, close, end, isOpen
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.newsclub.net.unix.AFSomeSocketChannel
configureBlocking, isBlocking
Methods inherited from interface java.nio.channels.InterruptibleChannel
close
Methods inherited from interface java.nio.channels.MulticastChannel
close
-
Constructor Details
-
AFDatagramChannel
Creates a newAFDatagramChannel
instance.- Parameters:
selectorProvider
- The correspondingSelectorProvider
.socket
- The correspondingSocket
.
-
-
Method Details
-
getAFSocket
Returns the correspondingSocket
.- Returns:
- The socket.
-
join
- Specified by:
join
in interfaceMulticastChannel
- Throws:
IOException
-
join
public final MembershipKey join(InetAddress group, NetworkInterface interf, InetAddress source) throws IOException - Specified by:
join
in interfaceMulticastChannel
- Throws:
IOException
-
bind
- Specified by:
bind
in interfaceNetworkChannel
- Specified by:
bind
in classDatagramChannel
- Throws:
IOException
-
socket
- Specified by:
socket
in classDatagramChannel
-
isBound
public final boolean isBound()Returns the binding state of the socket.- Returns:
- true if the socket successfully bound to an address
-
isConnected
public final boolean isConnected()- Specified by:
isConnected
in classDatagramChannel
-
connect
- Specified by:
connect
in classDatagramChannel
- Throws:
IOException
-
disconnect
- Specified by:
disconnect
in classDatagramChannel
- Throws:
IOException
-
getRemoteAddress
- Specified by:
getRemoteAddress
in classDatagramChannel
- Throws:
IOException
-
getRemoteSocketAddress
Description copied from interface:AFSomeSocket
Returns the socket's remote socket address, ornull
if unavailable/not connected, or if there was a problem retrieving it.- Specified by:
getRemoteSocketAddress
in interfaceAFSomeSocket
- Returns:
- The remote socket address, or
null
.
-
getLocalAddress
- Specified by:
getLocalAddress
in interfaceNetworkChannel
- Specified by:
getLocalAddress
in classDatagramChannel
- Throws:
IOException
-
getLocalSocketAddress
Description copied from interface:AFSomeSocketThing
Returns the socket's local socket address, ornull
if unavailable or if there was a problem retrieving it.- Specified by:
getLocalSocketAddress
in interfaceAFSomeSocketThing
- Returns:
- The local socket address, or
null
.
-
receive
- Specified by:
receive
in classDatagramChannel
- Throws:
IOException
-
send
- Specified by:
send
in classDatagramChannel
- Throws:
IOException
-
read
- Specified by:
read
in interfaceReadableByteChannel
- Specified by:
read
in classDatagramChannel
- Throws:
IOException
-
read
- Specified by:
read
in interfaceScatteringByteChannel
- Specified by:
read
in classDatagramChannel
- Throws:
IOException
-
write
- Specified by:
write
in interfaceWritableByteChannel
- Specified by:
write
in classDatagramChannel
- Throws:
IOException
-
write
- Specified by:
write
in interfaceGatheringByteChannel
- Specified by:
write
in classDatagramChannel
- Throws:
IOException
-
implCloseSelectableChannel
- Specified by:
implCloseSelectableChannel
in classAbstractSelectableChannel
- Throws:
IOException
-
implConfigureBlocking
- Specified by:
implConfigureBlocking
in classAbstractSelectableChannel
- Throws:
IOException
-
getAncillaryReceiveBufferSize
public final int getAncillaryReceiveBufferSize()Description copied from interface:AFSocketExtensions
Returns the size of the receive buffer for ancillary messages (in bytes).- Specified by:
getAncillaryReceiveBufferSize
in interfaceAFSocketExtensions
- Returns:
- The size.
-
setAncillaryReceiveBufferSize
public final void setAncillaryReceiveBufferSize(int size) Description copied from interface:AFSocketExtensions
Sets the size of the receive buffer for ancillary messages (in bytes). To disable handling ancillary messages, set it to 0 (default).- Specified by:
setAncillaryReceiveBufferSize
in interfaceAFSocketExtensions
- Parameters:
size
- The size.
-
ensureAncillaryReceiveBufferSize
public final void ensureAncillaryReceiveBufferSize(int minSize) Description copied from interface:AFSocketExtensions
Ensures a minimum ancillary receive buffer size.- Specified by:
ensureAncillaryReceiveBufferSize
in interfaceAFSocketExtensions
- Parameters:
minSize
- The minimum size (in bytes).
-
setOption
- Specified by:
setOption
in interfaceNetworkChannel
- Specified by:
setOption
in classDatagramChannel
- Throws:
IOException
-
getOption
- Specified by:
getOption
in interfaceNetworkChannel
- Throws:
IOException
-
supportedOptions
- Specified by:
supportedOptions
in interfaceNetworkChannel
-
getFileDescriptor
Description copied from interface:FileDescriptorAccess
Returns the correspondingFileDescriptor
.- Specified by:
getFileDescriptor
in interfaceFileDescriptorAccess
- Returns:
- The corresponding
FileDescriptor
. - Throws:
IOException
- on error.
-
isDeleteOnClose
public final boolean isDeleteOnClose()Checks if thisDatagramSocket
's bound filename should be removed uponAbstractInterruptibleChannel.close()
. Deletion is not guaranteed, especially when not supported (e.g., addresses in the abstract namespace).- Returns:
true
if an attempt is made to delete the socket file uponAbstractInterruptibleChannel.close()
.
-
setDeleteOnClose
public final void setDeleteOnClose(boolean b) Enables/disables deleting thisDatagramSocket
's bound filename uponAbstractInterruptibleChannel.close()
. Deletion is not guaranteed, especially when not supported (e.g., addresses in the abstract namespace).- Parameters:
b
- Enabled iftrue
.
-
setShutdownOnClose
public void setShutdownOnClose(boolean enabled) Description copied from interface:AFSomeSocketThing
Configures whether the socket should be shutdown uponCloseable.close()
, which is the default.- Specified by:
setShutdownOnClose
in interfaceAFSomeSocketThing
- Parameters:
enabled
-true
if enabled.
-
open
Opens a datagram channel. Thefamily
parameter specifies theprotocol family
of the channel's socket.If the
ProtocolFamily
is of anAFProtocolFamily
, orUNIX
, the corresponding junixsocket implementation is used. In all other cases, the call is delegated toDatagramChannel.open()
.- Parameters:
family
- The protocol family.- Returns:
- The new
DatagramChannel
. - Throws:
IOException
- on error.
-