Top Description Fields Constructors Methods
org.newsclub.net.unix

public abstract Class AFDatagramSocketImpl<A extends AFSocketAddress>

extends DatagramSocketImplShim
Class Inheritance
Known Direct Subclasses
org.newsclub.net.unix.AFGenericDatagramSocketImpl, org.newsclub.net.unix.AFUNIXDatagramSocketImpl
Annotations
@SuppressWarnings:PMD.CyclomaticComplexity
Type Parameters
<A>
The associated address type.
Static Imports
org.newsclub.net.unix.NativeUnixSocket.SHUT_RD_WR

A DatagramSocketImpl implemented by junixsocket.
Author
Christian Kohlschütter

Field Summary

Modifier and TypeField and Description
private final AFAddressFamily<@NonNull A>
pack-priv final AncillaryDataSupport
private final AtomicBoolean
private final AtomicBoolean
private final AFSocketCore
private AFSocketImplExtensions<A>
private int
private int
private final AtomicInteger
private final AFSocketType

Constructor Summary

AccessConstructor and Description
protected
AFDatagramSocketImpl(AFAddressFamily<@NonNull A>
The address family.
addressFamily
,
FileDescriptor
The file descriptor, or null.
fd
,
AFSocketType
The socket type.
socketType
)

Constructs a new AFDatagramSocketImpl using the given FileDescriptor (or null to create a new one).

Method Summary

Modifier and TypeMethod and Description
pack-priv final boolean
protected final void
bind(int
the local port
lport
,
InetAddress
the local address
laddr
)

Implements abstract java.net.DatagramSocketImpl.bind.

Binds a datagram socket to a local port and address.

pack-priv final void
bind(AFSocketAddress socketAddress)

protected final void
close()

Implements abstract java.net.DatagramSocketImpl.close.

Close the socket.

protected final void
connect(InetAddress
the remote InetAddress to connect to
address
,
int
the remote port number
port
)

Overrides java.net.DatagramSocketImpl.connect.

Connects a datagram socket to a remote destination.

pack-priv final void
connect(AFSocketAddress socketAddress)

protected final void
create()

Implements abstract java.net.DatagramSocketImpl.create.

Creates a datagram socket.

protected final void
disconnect()

Overrides java.net.DatagramSocketImpl.disconnect.

Disconnects a datagram socket from its remote destination.

protected final AFAddressFamily<@NonNull A>

Returns:

The family.
getAddressFamily
()

Returns the address family supported by this implementation.

pack-priv final AFSocketCore
protected final FileDescriptor
getFileDescriptor()

Overrides java.net.DatagramSocketImpl.getFileDescriptor.

Gets the datagram socket file descriptor.

protected final synchronized AFSocketImplExtensions<A>

Returns:

The helper instance.
getImplExtensions
()

Returns the internal helper instance for address-specific extensions.

pack-priv final int
pack-priv final @Nullable A
public Object
getOption(int
an int identifying the option to fetch
optID
)

Implements java.net.SocketOptions.getOption.

Fetch the value of an option.

pack-priv final int
pack-priv final @Nullable A
protected final int
getTimeToLive()

Implements abstract java.net.DatagramSocketImpl.getTimeToLive.

Retrieve the TTL (time-to-live) option.

protected final byte
getTTL()

Implements abstract java.net.DatagramSocketImpl.getTTL.

Deprecated

Retrieve the TTL (time-to-live) option.

pack-priv final boolean
pack-priv final boolean
pack-priv final boolean
protected final void
join(InetAddress
multicast address to join.
inetaddr
)

Implements abstract java.net.DatagramSocketImpl.join.

Join the multicast group.

protected final void
joinGroup(SocketAddress
address to join.
mcastaddr
,
NetworkInterface
specifies the local interface to receive multicast datagram packets
netIf
)

Implements abstract java.net.DatagramSocketImpl.joinGroup.

Join the multicast group.

protected final void
leave(InetAddress
multicast address to leave.
inetaddr
)

Implements abstract java.net.DatagramSocketImpl.leave.

Leave the multicast group.

protected final void
leaveGroup(SocketAddress
address to leave.
mcastaddr
,
NetworkInterface
specified the local interface to leave the group at
netIf
)

Implements abstract java.net.DatagramSocketImpl.leaveGroup.

Leave the multicast group.

protected final int
peek(InetAddress
an InetAddress object
i
)

Implements abstract java.net.DatagramSocketImpl.peek.

Peek at the packet to see who it is from.

protected final int
peekData(DatagramPacket
the Packet Received.
p
)

Implements abstract java.net.DatagramSocketImpl.peekData.

Peek at the packet to see who it is from.

pack-priv final int
read(ByteBuffer dst, ByteBuffer socketAddressBuffer)

protected final void
receive(DatagramPacket
the Packet Received.
p
)

Implements abstract java.net.DatagramSocketImpl.receive.

Receive the datagram packet.

pack-priv final A
private void
recv(DatagramPacket p, int options)

protected final void
send(DatagramPacket
the packet to be sent.
p
)

Implements abstract java.net.DatagramSocketImpl.send.

Sends a datagram packet.

pack-priv final int
public void
setOption(int
identifies the option
optID
,
Object
the parameter of the socket option
value
)

Implements java.net.SocketOptions.setOption.

Enable/disable the option specified by optID.

pack-priv final void
protected final void
setTimeToLive(int
an int specifying the time-to-live value
ttl
)

Implements abstract java.net.DatagramSocketImpl.setTimeToLive.

Set the TTL (time-to-live) option.

protected final void
setTTL(byte
a byte specifying the TTL value
ttl
)

Implements abstract java.net.DatagramSocketImpl.setTTL.

Deprecated

Set the TTL (time-to-live) option.

pack-priv final void
updatePorts(int local, int remote)

pack-priv final int
Inherited from org.newsclub.net.unix.DatagramSocketImplShim:
getOptionsetOptionsupportedOptions

Field Detail

addressFamilyback to summary
private final AFAddressFamily<@NonNull A> addressFamily
ancillaryDataSupportback to summary
pack-priv final AncillaryDataSupport ancillaryDataSupport
boundback to summary
private final AtomicBoolean bound
connectedback to summary
private final AtomicBoolean connected
coreback to summary
private final AFSocketCore core
implExtensionsback to summary
private AFSocketImplExtensions<A> implExtensions
localPortback to summary
private int localPort

Hides java.net.DatagramSocketImpl.localPort.

remotePortback to summary
private int remotePort
socketTimeoutback to summary
private final AtomicInteger socketTimeout
socketTypeback to summary
private final AFSocketType socketType

Constructor Detail

AFDatagramSocketImplback to summary
protected AFDatagramSocketImpl(AFAddressFamily<@NonNull A> addressFamily, FileDescriptor fd, AFSocketType socketType)

Constructs a new AFDatagramSocketImpl using the given FileDescriptor (or null to create a new one).

Parameters
addressFamily:AFAddressFamily<@NonNull A>

The address family.

fd:FileDescriptor

The file descriptor, or null.

socketType:AFSocketType

The socket type.

Annotations
@SuppressWarnings:this-escape

Method Detail

accept0back to summary
pack-priv final boolean accept0(AFDatagramSocketImpl<A> socket) throws IOException
Annotations
@SuppressWarnings:Finally
bindback to summary
protected final void bind(int lport, InetAddress laddr) throws SocketException

Implements abstract java.net.DatagramSocketImpl.bind.

Doc from java.net.DatagramSocketImpl.bind.

Binds a datagram socket to a local port and address.

Parameters
lport:int

the local port

laddr:InetAddress

the local address

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error.
bindback to summary
pack-priv final void bind(AFSocketAddress socketAddress) throws SocketException
closeback to summary
protected final void close()

Implements abstract java.net.DatagramSocketImpl.close.

Doc from java.net.DatagramSocketImpl.close.

Close the socket.

Annotations
@Override
connectback to summary
protected final void connect(InetAddress address, int port) throws SocketException

Overrides java.net.DatagramSocketImpl.connect.

Doc from java.net.DatagramSocketImpl.connect.

Connects a datagram socket to a remote destination. This associates the remote address with the local socket so that datagrams may only be sent to this destination and received from this destination. This may be overridden to call a native system connect.

If the remote destination to which the socket is connected does not exist, or is otherwise unreachable, and if an ICMP destination unreachable packet has been received for that address, then a subsequent call to send or receive may throw a PortUnreachableException. Note, there is no guarantee that the exception will be thrown.

Parameters
address:InetAddress

the remote InetAddress to connect to

port:int

the remote port number

Annotations
@Override
Exceptions
SocketException:
may be thrown if the socket cannot be connected to the remote destination
connectback to summary
pack-priv final void connect(AFSocketAddress socketAddress) throws IOException
createback to summary
protected final void create() throws SocketException

Implements abstract java.net.DatagramSocketImpl.create.

Doc from java.net.DatagramSocketImpl.create.

Creates a datagram socket.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error.
disconnectback to summary
protected final void disconnect()

Overrides java.net.DatagramSocketImpl.disconnect.

Doc from java.net.DatagramSocketImpl.disconnect.

Disconnects a datagram socket from its remote destination.

Annotations
@Override
getAddressFamilyback to summary
protected final AFAddressFamily<@NonNull A> getAddressFamily()

Returns the address family supported by this implementation.

Returns:AFAddressFamily<@NonNull A>

The family.

getCoreback to summary
pack-priv final AFSocketCore getCore()
getFileDescriptorback to summary
protected final FileDescriptor getFileDescriptor()

Overrides java.net.DatagramSocketImpl.getFileDescriptor.

Doc from java.net.DatagramSocketImpl.getFileDescriptor.

Gets the datagram socket file descriptor.

Returns:FileDescriptor

a FileDescriptor object representing the datagram socket file descriptor

Annotations
@Override
getImplExtensionsback to summary
protected final synchronized AFSocketImplExtensions<A> getImplExtensions()

Returns the internal helper instance for address-specific extensions.

Returns:AFSocketImplExtensions<A>

The helper instance.

Exceptions
UnsupportedOperationException:
if such extensions are not supported for this address type.
getLocalPort1back to summary
pack-priv final int getLocalPort1()
getLocalSocketAddressback to summary
pack-priv final @Nullable A getLocalSocketAddress()
getOptionback to summary
public Object getOption(int optID) throws SocketException

Implements java.net.SocketOptions.getOption.

Doc from java.net.SocketOptions.getOption.

Fetch the value of an option. Binary options will return Boolean#TRUE if enabled, Boolean#FALSE if disabled, e.g.:

SocketImpl s; ... Boolean noDelay = (Boolean)(s.getOption(TCP_NODELAY)); if (noDelay.booleanValue()) { // true if TCP_NODELAY is enabled... ... }
SocketImpl s;
...
Boolean noDelay = (Boolean)(s.getOption(TCP_NODELAY));
if (noDelay.booleanValue()) {
    // true if TCP_NODELAY is enabled...
...
}

For options that take a particular type as a parameter, this method will return the parameter's value, else it will return Boolean#FALSE:

Object o = s.getOption(SO_LINGER); if (o instanceof Integer) { System.out.print("Linger time is " + ((Integer)o).intValue()); } else { // the true type of o is java.lang.Boolean.FALSE; }
Object o = s.getOption(SO_LINGER);
if (o instanceof Integer) {
    System.out.print("Linger time is " + ((Integer)o).intValue());
} else {
  // the true type of o is java.lang.Boolean.FALSE;
}
Parameters
optID:int

an int identifying the option to fetch

Returns:Object

the value of the option

Annotations
@Override
Exceptions
SocketException:
if the socket is closed or if optID is unknown along the protocol stack
getRemotePortback to summary
pack-priv final int getRemotePort()
getRemoteSocketAddressback to summary
pack-priv final @Nullable A getRemoteSocketAddress()
getTimeToLiveback to summary
protected final int getTimeToLive() throws IOException

Implements abstract java.net.DatagramSocketImpl.getTimeToLive.

Doc from java.net.DatagramSocketImpl.getTimeToLive.

Retrieve the TTL (time-to-live) option.

Returns:int

an int representing the time-to-live value

Annotations
@Override
Exceptions
IOException:
if an I/O exception occurs while retrieving the time-to-live option
getTTLback to summary
protected final byte getTTL() throws IOException

Implements abstract java.net.DatagramSocketImpl.getTTL.

Doc from java.net.DatagramSocketImpl.getTTL.

Deprecated

Retrieve the TTL (time-to-live) option.

Returns:byte

a byte representing the TTL value

Annotations
@Override
@Deprecated
Exceptions
IOException:
if an I/O exception occurs while retrieving the time-to-live option
isBoundback to summary
pack-priv final boolean isBound()
isClosedback to summary
pack-priv final boolean isClosed()
isConnectedback to summary
pack-priv final boolean isConnected()
joinback to summary
protected final void join(InetAddress inetaddr) throws IOException

Implements abstract java.net.DatagramSocketImpl.join.

Doc from java.net.DatagramSocketImpl.join.

Join the multicast group.

Parameters
inetaddr:InetAddress

multicast address to join.

Annotations
@Override
Exceptions
IOException:
if an I/O exception occurs while joining the multicast group.
joinGroupback to summary
protected final void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf) throws IOException

Implements abstract java.net.DatagramSocketImpl.joinGroup.

Doc from java.net.DatagramSocketImpl.joinGroup.

Join the multicast group.

Parameters
mcastaddr:SocketAddress

address to join.

netIf:NetworkInterface

specifies the local interface to receive multicast datagram packets

Annotations
@Override
Exceptions
IOException:
if an I/O exception occurs while joining the multicast group
leaveback to summary
protected final void leave(InetAddress inetaddr) throws IOException

Implements abstract java.net.DatagramSocketImpl.leave.

Doc from java.net.DatagramSocketImpl.leave.

Leave the multicast group.

Parameters
inetaddr:InetAddress

multicast address to leave.

Annotations
@Override
Exceptions
IOException:
if an I/O exception occurs while leaving the multicast group.
leaveGroupback to summary
protected final void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf) throws IOException

Implements abstract java.net.DatagramSocketImpl.leaveGroup.

Doc from java.net.DatagramSocketImpl.leaveGroup.

Leave the multicast group.

Parameters
mcastaddr:SocketAddress

address to leave.

netIf:NetworkInterface

specified the local interface to leave the group at

Annotations
@Override
Exceptions
IOException:
if an I/O exception occurs while leaving the multicast group
peekback to summary
protected final int peek(InetAddress i) throws IOException

Implements abstract java.net.DatagramSocketImpl.peek.

Doc from java.net.DatagramSocketImpl.peek.

Peek at the packet to see who it is from. Updates the specified InetAddress to the address which the packet came from.

Parameters
i:InetAddress

an InetAddress object

Returns:int

the port number which the packet came from.

Annotations
@Override
Exceptions
IOException:
if an I/O exception occurs
peekDataback to summary
protected final int peekData(DatagramPacket p) throws IOException

Implements abstract java.net.DatagramSocketImpl.peekData.

Doc from java.net.DatagramSocketImpl.peekData.

Peek at the packet to see who it is from. The data is copied into the specified DatagramPacket. The data is returned, but not consumed, so that a subsequent peekData/receive operation will see the same data.

Parameters
p:DatagramPacket

the Packet Received.

Returns:int

the port number which the packet came from.

Annotations
@Override
Exceptions
IOException:
if an I/O exception occurs
readback to summary
pack-priv final int read(ByteBuffer dst, ByteBuffer socketAddressBuffer) throws IOException
receiveback to summary
protected final void receive(DatagramPacket p) throws IOException

Implements abstract java.net.DatagramSocketImpl.receive.

Doc from java.net.DatagramSocketImpl.receive.

Receive the datagram packet.

Parameters
p:DatagramPacket

the Packet Received.

Annotations
@Override
Exceptions
IOException:
if an I/O exception occurs while receiving the datagram packet.
receiveback to summary
pack-priv final A receive(ByteBuffer dst) throws IOException
Annotations
@SuppressWarnings:unchecked
recvback to summary
private void recv(DatagramPacket p, int options) throws IOException
Annotations
@SuppressWarnings:PMD.NcssCount, PMD.CognitiveComplexity, PMD.CyclomaticComplexity, PMD.NPathComplexity
@SuppressFBWarnings:NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE
sendback to summary
protected final void send(DatagramPacket p) throws IOException

Implements abstract java.net.DatagramSocketImpl.send.

Doc from java.net.DatagramSocketImpl.send.

Sends a datagram packet. The packet contains the data and the destination address to send the packet to.

Parameters
p:DatagramPacket

the packet to be sent.

Annotations
@SuppressWarnings:PMD.NcssCount, PMD.CognitiveComplexity, PMD.CyclomaticComplexity, PMD.NPathComplexity
@SuppressFBWarnings:NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE
@Override
Exceptions
IOException:
if an I/O exception occurs while sending the datagram packet.
sendback to summary
pack-priv final int send(ByteBuffer src, SocketAddress target) throws IOException
setOptionback to summary
public void setOption(int optID, Object value) throws SocketException

Implements java.net.SocketOptions.setOption.

Doc from java.net.SocketOptions.setOption.

Enable/disable the option specified by optID. If the option is to be enabled, and it takes an option-specific "value", this is passed in value. The actual type of value is option-specific, and it is an error to pass something that isn't of the expected type:

SocketImpl s; ... s.setOption(SO_LINGER, Integer.valueOf(10)); // OK - set SO_LINGER w/ timeout of 10 sec. s.setOption(SO_LINGER, Double.valueOf(10)); // ERROR - expects java.lang.Integer
SocketImpl s;
...
s.setOption(SO_LINGER, Integer.valueOf(10));
   // OK - set SO_LINGER w/ timeout of 10 sec.
s.setOption(SO_LINGER, Double.valueOf(10));
   // ERROR - expects java.lang.Integer
If the requested option is binary, it can be set using this method by a Boolean:
s.setOption(TCP_NODELAY, Boolean.TRUE); // OK - enables TCP_NODELAY, a binary option
s.setOption(TCP_NODELAY, Boolean.TRUE);
   // OK - enables TCP_NODELAY, a binary option
Any option can be disabled using this method with a Boolean#FALSE:
s.setOption(TCP_NODELAY, Boolean.FALSE); // OK - disables TCP_NODELAY s.setOption(SO_LINGER, Boolean.FALSE); // OK - disables SO_LINGER
s.setOption(TCP_NODELAY, Boolean.FALSE);
   // OK - disables TCP_NODELAY
s.setOption(SO_LINGER, Boolean.FALSE);
   // OK - disables SO_LINGER
For an option that has a notion of on and off, and requires a non-boolean parameter, setting its value to anything other than Boolean#FALSE implicitly enables it.
Parameters
optID:int

identifies the option

value:Object

the parameter of the socket option

Annotations
@Override
Exceptions
SocketException:
if the option is unrecognized, the socket is closed, or some low-level error occurred
setSocketAddressback to summary
pack-priv final void setSocketAddress(AFSocketAddress socketAddress)
setTimeToLiveback to summary
protected final void setTimeToLive(int ttl) throws IOException

Implements abstract java.net.DatagramSocketImpl.setTimeToLive.

Doc from java.net.DatagramSocketImpl.setTimeToLive.

Set the TTL (time-to-live) option.

Parameters
ttl:int

an int specifying the time-to-live value

Annotations
@Override
Exceptions
IOException:
if an I/O exception occurs while setting the time-to-live option.
setTTLback to summary
protected final void setTTL(byte ttl) throws IOException

Implements abstract java.net.DatagramSocketImpl.setTTL.

Doc from java.net.DatagramSocketImpl.setTTL.

Deprecated

Set the TTL (time-to-live) option.

Parameters
ttl:byte

a byte specifying the TTL value

Annotations
@Override
@Deprecated
Exceptions
IOException:
if an I/O exception occurs while setting the time-to-live option.
updatePortsback to summary
pack-priv final void updatePorts(int local, int remote)
writeback to summary
pack-priv final int write(ByteBuffer src) throws IOException