Top Description Inners Fields Constructors Methods
sun.nio.ch

pack-priv Class DatagramChannelImpl

extends DatagramChannel
implements SelChImpl
Class Inheritance
All Implemented Interfaces
sun.nio.ch.SelChImpl, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable
Known Direct Subclasses
sun.nio.ch.InheritedChannel.InheritedDatagramChannelImpl
Imports
java.io.FileDescriptor, .IOException, .InterruptedIOException, .UncheckedIOException, java.lang.invoke.MethodHandles, .VarHandle, java.lang.ref.Cleaner.Cleanable, java.lang.reflect.Method, java.net.DatagramPacket, .DatagramSocket, .Inet4Address, .Inet6Address, .InetAddress, .InetSocketAddress, .NetworkInterface, .PortUnreachableException, .ProtocolFamily, .SocketAddress, .SocketException, .SocketOption, .SocketTimeoutException, .StandardProtocolFamily, .StandardSocketOptions, java.nio.ByteBuffer, java.nio.channels.AlreadyBoundException, .AlreadyConnectedException, .AsynchronousCloseException, .ClosedChannelException, .DatagramChannel, .IllegalBlockingModeException, .MembershipKey, .NotYetConnectedException, .SelectionKey, java.nio.channels.spi.AbstractSelectableChannel, .SelectorProvider, java.security.AccessController, .PrivilegedExceptionAction, java.util.Collections, .HashMap, .HashSet, .Map, .Objects, .Set, java.util.concurrent.TimeUnit, java.util.concurrent.locks.ReentrantLock, java.util.function.Consumer, jdk.internal.access.JavaNioAccess, .SharedSecrets, jdk.internal.ref.CleanerFactory, sun.net.ResourceManager, sun.net.ext.ExtendedSocketOptions, sun.net.util.IPAddressUtil

An implementation of DatagramChannels.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
DatagramChannelImpl.AbstractSelectableChannels

Defines static methods to access AbstractSelectableChannel non-public members.

private static class
DatagramChannelImpl.DatagramPackets

Defines static methods to get/set DatagramPacket fields and workaround DatagramPacket deficiencies.

private static class

Field Summary

Modifier and TypeField and Description
private InetSocketAddress
private NativeSocketAddress
private final Cleaner.Cleanable
private final ProtocolFamily
private final FileDescriptor
private final int
private volatile boolean
private InetSocketAddress
private final boolean
private boolean
private InetSocketAddress
private static final NativeDispatcher
private static final JavaNioAccess
private int
private InetSocketAddress
private long
private final ReentrantLock
private MembershipRegistry
private InetSocketAddress
private boolean
private static final VarHandle
private volatile DatagramSocket
private NativeSocketAddress
private static final int
private static final int
private static final int
private static final int
private int
private final Object
private final NativeSocketAddress
private final ReentrantLock
private long

Constructor Summary

AccessConstructor and Description
pack-priv
DatagramChannelImpl(SelectorProvider sp, boolean interruptible)

pack-priv
DatagramChannelImpl(SelectorProvider sp, ProtocolFamily family, boolean interruptible)

pack-priv

Method Summary

Modifier and TypeMethod and Description
private SocketAddress

Returns:

remote address if connected
beginRead
(boolean
true if configured blocking
blocking
,
boolean
true if the socket must be connected
mustBeConnected
)

Marks the beginning of a read operation that might block.

private SocketAddress

Returns:

remote address if connected
beginWrite
(boolean
true if configured blocking
blocking
,
boolean
true if the socket must be connected
mustBeConnected
)

Marks the beginning of a write operation that might block.

public DatagramChannel
bind(SocketAddress
The address to bind the socket, or null to bind the socket to an automatically assigned socket address
local
)

Implements abstract java.nio.channels.DatagramChannel.bind.

Implements java.nio.channels.NetworkChannel.bind.

Binds the channel's socket to a local address.

private void
pack-priv void
block(MembershipKeyImpl key, InetAddress source)

Block datagrams from the given source.

pack-priv void
blockingReceive(DatagramPacket p, long nanos)

Receives a datagram.

pack-priv void
blockingSend(DatagramPacket p)

Sends a datagram.

private void
configureSocketNonBlocking()

Ensures that the socket is configured non-blocking.

private void
configureSocketNonBlockingIfVirtualThread()

Ensures that the socket is configured non-blocking when on a virtual thread.

public DatagramChannel
connect(SocketAddress
The remote address to which this channel is to be connected
sa
)

Implements abstract java.nio.channels.DatagramChannel.connect.

Connects this channel's socket.

pack-priv DatagramChannel
connect(SocketAddress
the remote address to which this channel is to be connected
sa
,
boolean
true to check if the channel is already connected.
check
)

Connects the channel's socket.

public DatagramChannel
disconnect()

Implements abstract java.nio.channels.DatagramChannel.disconnect.

Disconnects this channel's socket.

private static native void
disconnect0(FileDescriptor fd, boolean isIPv6)

pack-priv void
private void
endRead(boolean blocking, boolean completed)

Marks the end of a read operation that may have blocked.

private void
endWrite(boolean blocking, boolean completed)

Marks the end of a write operation that may have blocked.

private void
private ProtocolFamily
familyFor(SocketOption<?> name)

Returns the protocol family to specify to set/getSocketOption for the given socket option.

pack-priv MembershipKey
findMembership(InetAddress group, NetworkInterface interf)

Finds an existing membership of a multicast group.

public FileDescriptor
public int
public SocketAddress
getLocalAddress()

Implements abstract java.nio.channels.DatagramChannel.getLocalAddress.

Implements java.nio.channels.NetworkChannel.getLocalAddress.

Returns the socket address that this channel's socket is bound to.

public <T> T
getOption(SocketOption<T>
The socket option
name
)

Implements java.nio.channels.NetworkChannel.getOption.

Returns the value of a socket option.

public SocketAddress
getRemoteAddress()

Implements abstract java.nio.channels.DatagramChannel.getRemoteAddress.

Returns the remote address to which this channel's socket is connected.

private void
implCloseBlockingMode()

Closes this channel when configured in blocking mode.

private void
implCloseNonBlockingMode()

Closes this channel when configured in non-blocking mode.

protected void
implCloseSelectableChannel()

Implements abstract java.nio.channels.spi.AbstractSelectableChannel.implCloseSelectableChannel.

Invoked by implCloseChannel to close the channel.

protected void
implConfigureBlocking(boolean
If true then this channel will be placed in blocking mode; if false then it will be placed non-blocking mode
block
)

Implements abstract java.nio.channels.spi.AbstractSelectableChannel.implConfigureBlocking.

Adjusts this channel's blocking mode.

private MembershipKey
innerJoin(InetAddress group, NetworkInterface interf, InetAddress source)

Joins channel's socket to the given group/interface and optional source address.

public boolean
isConnected()

Implements abstract java.nio.channels.DatagramChannel.isConnected.

Tells whether or not this channel's socket is connected.

public MembershipKey
join(InetAddress
The multicast address to join
group
,
NetworkInterface
The network interface on which to join the group
interf
)

Implements java.nio.channels.MulticastChannel.join.

Joins a multicast group to begin receiving all datagrams sent to the group, returning a membership key.

public MembershipKey
join(InetAddress
The multicast address to join
group
,
NetworkInterface
The network interface on which to join the group
interf
,
InetAddress
The source address
source
)

Implements java.nio.channels.MulticastChannel.join.

Joins a multicast group to begin receiving datagrams sent to the group from a given source address.

public void
pack-priv InetSocketAddress
private void
lockedConfigureBlocking(boolean block)

Adjusts the blocking mode.

public void
park(int
the event to poll
event
,
long
the timeout to wait; <= 0 to wait indefinitely
nanos
)

Overrides default sun.nio.ch.SelChImpl.park.

Disables the current thread for scheduling purposes until this channel is ready for I/O, or asynchronously closed, for up to the specified waiting time.

public int
read(ByteBuffer
The buffer into which bytes are to be transferred
buf
)

Implements abstract java.nio.channels.DatagramChannel.read.

Implements java.nio.channels.ReadableByteChannel.read.

Reads a datagram from this channel.

public long
read(ByteBuffer[]
The buffers into which bytes are to be transferred
dsts
,
int
The offset within the buffer array of the first buffer into which bytes are to be transferred; must be non-negative and no larger than dsts.length
offset
,
int
The maximum number of buffers to be accessed; must be non-negative and no larger than dsts.length - offset
length
)

Implements abstract java.nio.channels.DatagramChannel.read.

Implements java.nio.channels.ScatteringByteChannel.read.

Reads a datagram from this channel.

public SocketAddress
receive(ByteBuffer
The buffer into which the datagram is to be transferred
dst
)

Implements abstract java.nio.channels.DatagramChannel.receive.

Receives a datagram via this channel.

private int
receive(ByteBuffer dst, boolean
true if the channel is connected
connected
)

Receives a datagram into the buffer.

private static native int
receive0(FileDescriptor fd, long address, int len, long senderAddress, boolean connected)

private int
receiveIntoNativeBuffer(ByteBuffer bb, int rem, int pos, boolean connected)

Receives a datagram into a direct buffer.

private static Runnable
releaserFor(FileDescriptor fd, NativeSocketAddress... sockAddrs)

Returns an action to release the given file descriptor and socket addresses.

pack-priv InetSocketAddress
private void
repairSocket(InetSocketAddress target)

"Repair" the channel's socket after a disconnect that didn't restore the local address.

public int
send(ByteBuffer
The buffer containing the datagram to be sent
src
,
SocketAddress
The address to which the datagram is to be sent
target
)

Implements abstract java.nio.channels.DatagramChannel.send.

Sends a datagram via this channel.

private int
private static native int
send0(FileDescriptor fd, long address, int len, long targetAddress, int targetAddressLen)

private int
sendFromNativeBuffer(FileDescriptor fd, ByteBuffer bb, InetSocketAddress target)

Send a datagram contained in a direct buffer.

public <T> DatagramChannel
setOption(SocketOption<T>
The socket option
name
,
T
The value of the socket option. A value of null may be a valid value for some socket options.
value
)

Implements abstract java.nio.channels.DatagramChannel.setOption.

Implements java.nio.channels.NetworkChannel.setOption.

Sets the value of a socket option.

public DatagramSocket
socket()

Implements abstract java.nio.channels.DatagramChannel.socket.

Retrieves a datagram socket associated with this channel.

private InetSocketAddress
sourceSocketAddress()

Return an InetSocketAddress to represent the source/sender socket address in sourceSockAddr.

public final Set<SocketOption<?>>
supportedOptions()

Implements java.nio.channels.NetworkChannel.supportedOptions.

Returns a set of the socket options supported by this channel.

private int
targetSocketAddress(InetSocketAddress isa)

Encodes the given InetSocketAddress into targetSockAddr, returning the length of the sockaddr structure (sizeof struct sockaddr or sockaddr6).

public boolean
translateAndSetReadyOps(int ops, SelectionKeyImpl ski)

Implements sun.nio.ch.SelChImpl.translateAndSetReadyOps.

Sets the specified ops if present in interestOps.

public boolean
translateAndUpdateReadyOps(int ops, SelectionKeyImpl ski)

Implements sun.nio.ch.SelChImpl.translateAndUpdateReadyOps.

Adds the specified ops if present in interestOps.

public int
translateInterestOps(int ops)

Implements sun.nio.ch.SelChImpl.translateInterestOps.

Translates an interest operation set into a native poll event set

public boolean
translateReadyOps(int ops, int initialOps, SelectionKeyImpl ski)

Translates native poll revent set into a ready operation set

private ByteBuffer

Returns:

a direct buffer containing the datagram or null if channel is closed
tryBlockingReceive
(boolean
if the channel's socket is connected
connected
,
int
the maximum size of the datagram to receive
len
,
long
the timeout, should be Long.MAX_VALUE for untimed
nanos
)

Attempt to receive a datagram.

private boolean
tryClose()

Closes the socket if there are no I/O operations in progress and the channel is not registered with a Selector.

private void
tryFinishClose()

Invokes tryClose to attempt to close the socket.

private boolean

Returns:

true if the blocking mode was adjusted
tryLockedConfigureBlocking
(boolean block)

Attempts to adjust the blocking mode if the channel is open.

pack-priv void
unblock(MembershipKeyImpl key, InetAddress source)

Unblock the given source.

private SocketAddress
untrustedReceive(ByteBuffer dst)

Receives a datagram into an untrusted buffer.

public int
write(ByteBuffer
The buffer from which bytes are to be retrieved
buf
)

Implements abstract java.nio.channels.DatagramChannel.write.

Implements java.nio.channels.WritableByteChannel.write.

Writes a datagram to this channel.

public long
write(ByteBuffer[]
The buffers from which bytes are to be retrieved
srcs
,
int
The offset within the buffer array of the first buffer from which bytes are to be retrieved; must be non-negative and no larger than srcs.length
offset
,
int
The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offset
length
)

Implements abstract java.nio.channels.DatagramChannel.write.

Implements java.nio.channels.GatheringByteChannel.write.

Writes a datagram to this channel.

Inherited from java.nio.channels.DatagramChannel:
openopenreadvalidOpswrite