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

public abstract Class AFServerSocket<A extends AFSocketAddress>

extends ServerSocket
implements AFSomeSocketThing
Class Inheritance
All Implemented Interfaces
org.newsclub.net.unix.AFSomeSocketThing, org.newsclub.net.unix.FileDescriptorAccess, java.io.Closeable, java.lang.AutoCloseable
Known Direct Subclasses
org.newsclub.net.unix.AFUNIXServerSocket, org.newsclub.net.unix.AFGenericServerSocket
Annotations
@SuppressWarnings:PMD.CyclomaticComplexity, PMD.CouplingBetweenObjects
Type Parameters
<A>
The concrete AFSocketAddress that is supported by this type.
Imports
java.io.Closeable, .File, .FileDescriptor, .IOException, java.net.InetAddress, .ServerSocket, .SocketAddress, .SocketException, .SocketOption, .SocketOptions, java.nio.channels.IllegalBlockingModeException, java.util.Objects, .Set, java.util.concurrent.atomic.AtomicBoolean, org.eclipse.jdt.annotation.NonNull, .Nullable, com.kohlschutter.annotations.compiletime.SuppressFBWarnings

The server part of a junixsocket socket.
Author
Christian Kohlschütter

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
AFServerSocket.Constructor<
The concrete AFSocketAddress that is supported by this type.
A extends AFSocketAddress
>

The constructor of the concrete subclass.

Field Summary

Modifier and TypeField and Description
private @Nullable SocketAddressFilter
private @Nullable A
private final AFServerSocketChannel<A>
private final Closeables
private final AtomicBoolean
private final AtomicBoolean
private final AtomicBoolean
private final AFSocketImpl<A>

Constructor Summary

AccessConstructor and Description
protected
AFServerSocket()

Constructs a new, unconnected instance.

protected
AFServerSocket(FileDescriptor
The file descriptor, or null.
fdObj
)

Constructs a new instance, optionally associated with the given file descriptor.

Method Summary

Modifier and TypeMethod and Description
public AFSocket<A>
accept()

Overrides java.net.ServerSocket.accept.

Listens for a connection to be made to this socket and accepts it.

pack-priv AFSocket<A>
accept1(boolean throwOnFail)

public final void
addCloseable(Closeable
The closeable.
closeable
)

Registers a Closeable that should be closed when this socket is closed.

protected final AFAddressFamily<A>

Returns:

The family.
addressFamily
()

Returns the address family supported by this implementation.

public final void
bind(SocketAddress
The IP address and port number to bind to.
endpoint
)

Overrides java.net.ServerSocket.bind.

Binds the ServerSocket to a specific address (IP address and port number).

public final void
bind(SocketAddress
The IP address and port number to bind to.
endpoint
,
int
requested maximum length of the queue of incoming connections.
backlog
)

Overrides java.net.ServerSocket.bind.

Binds the ServerSocket to a specific address (IP address and port number).

public final AFServerSocket<A>

Returns:

This instance.
bindHook
(SocketAddressFilter
The function that gets called for each bind call.
hook
)

Sets the hook for any subsequent call to bind(SocketAddress) and bind(SocketAddress, int) to be the given function.

protected static <
The concrete AFSocketAddress that is supported by this type.
A extends AFSocketAddress
>
AFServerSocket<A>

Returns:

The new, bound AFServerSocket.
bindOn
(AFServerSocket.Constructor<A>
The constructor of the concrete subclass.
instanceSupplier
,
final AFSocketAddress
The socket file to bind to.
addr
)

Returns a new ServerSocket that is bound to the given AFSocketAddress.

protected static <
The concrete AFSocketAddress that is supported by this type.
A extends AFSocketAddress
>
AFServerSocket<A>

Returns:

The new, bound AFServerSocket.
bindOn
(AFServerSocket.Constructor<A>
The constructor of the concrete subclass.
instanceSupplier
,
final A
The socket file to bind to.
addr
,
boolean
If true, the socket file (if the address points to a file) will be deleted upon close.
deleteOnClose
)

Returns a new ServerSocket that is bound to the given AFSocketAddress.

private synchronized @Nullable A
public void
close()

Overrides java.net.ServerSocket.close.

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

public final AFServerSocket<A>

Returns:

This AFServerSocket.
forceBindAddress
(SocketAddress
The forced endpoint address.
endpoint
)

Forces the address to be used for any subsequent call to bind(SocketAddress) to be the given one, regardless of what'll be passed to bind(SocketAddress, int), but doesn't bind yet.

protected static <
The concrete AFSocketAddress that is supported by this type.
A extends AFSocketAddress
>
AFServerSocket<A>

Returns:

The new, yet unbound AFServerSocket.
forceBindOn
(AFServerSocket.Constructor<A>
The constructor of the concrete subclass.
instanceSupplier
,
final A
The address to use.
forceAddr
)

Returns a new, unbound ServerSocket that will always bind to the given address, regardless of any socket address used in a call to bind.

pack-priv final AFSocketImpl<A>
public AFServerSocketChannel<A>
getChannel()

Overrides java.net.ServerSocket.getChannel.

Returns the unique java.nio.channels.ServerSocketChannel object associated with this socket, if any.

public final FileDescriptor
public InetAddress
getInetAddress()

Overrides java.net.ServerSocket.getInetAddress.

Returns the local address of this server socket.

public final int
getLocalPort()

Overrides java.net.ServerSocket.getLocalPort.

Returns the port number on which this socket is listening.

public final @Nullable A
getLocalSocketAddress()

Overrides java.net.ServerSocket.getLocalSocketAddress.

Implements org.newsclub.net.unix.AFSomeSocketThing.getLocalSocketAddress.

Returns the socket's local socket address, or null if unavailable or if there was a problem retrieving it.

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

Overrides java.net.ServerSocket.getOption.

Returns the value of a socket option.

public synchronized int
getReceiveBufferSize()

Overrides java.net.ServerSocket.getReceiveBufferSize.

Gets the value of the SO_RCVBUF option for this ServerSocket, that is the proposed buffer size that will be used for Sockets accepted from this ServerSocket.

public boolean
public int
public final boolean
isBound()

Overrides java.net.ServerSocket.isBound.

Returns the binding state of the ServerSocket.

public final boolean
isClosed()

Overrides java.net.ServerSocket.isClosed.

Returns the closed state of the ServerSocket.

public final boolean

Returns:

true if an attempt is made to delete the socket file upon close().
isDeleteOnClose
()

Checks if this AFServerSocket's file should be removed upon close().

public boolean

Returns:

true iff still valid.
isLocalSocketAddressValid
()

Checks if the local socket address returned by getLocalSocketAddress() is still valid.

public static boolean

Returns:

true if supported.
isSupported
()

Checks whether everything is setup to support junixsocket sockets.

protected abstract AFServerSocketChannel<A>

Returns:

The new instance.
newChannel
()

Creates a new AFServerSocketChannel for this socket.

protected abstract AFSocketImpl<A>

Returns:

The new instance.
newImpl
(FileDescriptor
The file descriptor.
fdObj
)

Creates a new AFSocketImpl.

protected static <
The concrete AFSocketAddress that is supported by this type.
A extends AFSocketAddress
>
AFServerSocket<A>

Returns:

The new instance.
newInstance
(AFServerSocket.Constructor<A>
The subclass constructor.
instanceSupplier
)

Creates a new AFServerSocket instance, using the given subclass constructor.

protected static <
The concrete AFSocketAddress that is supported by this type.
A extends AFSocketAddress
>
AFServerSocket<A>

Returns:

The new instance.
newInstance
(AFServerSocket.Constructor<A>
The subclass constructor.
instanceSupplier
,
FileDescriptor
The file descriptor.
fdObj
,
int
The local port.
localPort
,
int
The remote port.
remotePort
)

Creates a new AFServerSocket instance, using the given subclass constructor.

protected abstract AFSocket<A>

Returns:

The new instance.
newSocketInstance
()

Returns a new AFSocket instance.

public final void
removeCloseable(Closeable
The closeable.
closeable
)

Unregisters a previously registered Closeable.

pack-priv final synchronized void
public final void
setDeleteOnClose(boolean
Enabled if true.
b
)

Enables/disables deleting this AFServerSocket's file (or other resource type) upon close().

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

Overrides java.net.ServerSocket.setOption.

Sets the value of a socket option.

public void
setPerformancePreferences(int
An int expressing the relative importance of a short connection time
connectionTime
,
int
An int expressing the relative importance of low latency
latency
,
int
An int expressing the relative importance of high bandwidth
bandwidth
)

Overrides java.net.ServerSocket.setPerformancePreferences.

Sets performance preferences for this ServerSocket.

public synchronized void
setReceiveBufferSize(int
the size to which to set the receive buffer size. This value must be greater than 0.
size
)

Overrides java.net.ServerSocket.setReceiveBufferSize.

Sets a default proposed value for the SO_RCVBUF option for sockets accepted from this ServerSocket.

public void
setReuseAddress(boolean
whether to enable or disable the socket option
on
)

Overrides java.net.ServerSocket.setReuseAddress.

Enable/disable the SO_REUSEADDR socket option.

public void
setShutdownOnClose(boolean
true if enabled.
enabled
)

Implements org.newsclub.net.unix.AFSomeSocketThing.setShutdownOnClose.

Configures whether the socket should be shutdown upon close(), which is the default.

public void
setSoTimeout(int
the specified timeout, in milliseconds
timeout
)

Overrides java.net.ServerSocket.setSoTimeout.

Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.

public Set<SocketOption<?>>
supportedOptions()

Overrides java.net.ServerSocket.supportedOptions.

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

public String
toString()

Overrides java.net.ServerSocket.toString.

Returns the implementation address and implementation port of this socket as a String.

Inherited from java.net.ServerSocket:
implAcceptsetSocketFactory

Field Detail

bindFilterback to summary
private @Nullable SocketAddressFilter bindFilter
boundEndpointback to summary
private @Nullable A boundEndpoint
channelback to summary
private final AFServerSocketChannel<A> channel
Annotations
@SuppressWarnings:this-escape
closeablesback to summary
private final Closeables closeables
closedback to summary
private final AtomicBoolean closed

Hides java.net.ServerSocket.closed.

createdback to summary
private final AtomicBoolean created

Hides java.net.ServerSocket.created.

deleteOnCloseback to summary
private final AtomicBoolean deleteOnClose
implementationback to summary
private final AFSocketImpl<A> implementation

Constructor Detail

AFServerSocketback to summary
protected AFServerSocket() throws IOException

Constructs a new, unconnected instance.

Annotations
@SuppressFBWarnings:CT_CONSTRUCTOR_THROW
Exceptions
IOException:
if the operation fails.
AFServerSocketback to summary
protected AFServerSocket(FileDescriptor fdObj) throws IOException

Constructs a new instance, optionally associated with the given file descriptor.

Parameters
fdObj:FileDescriptor

The file descriptor, or null.

Annotations
@SuppressWarnings:this-escape, PMD.ConstructorCallsOverridableMethod
@SuppressFBWarnings:CT_CONSTRUCTOR_THROW
Exceptions
IOException:
if the operation fails.

Method Detail

acceptback to summary
public AFSocket<A> accept() throws IOException

Overrides java.net.ServerSocket.accept.

Doc from java.net.ServerSocket.accept.

Listens for a connection to be made to this socket and accepts it. The method blocks until a connection is made.

This method is interruptible in the following circumstances:

  1. The socket is associated with a ServerSocketChannel. In that case, interrupting a thread accepting a connection will close the underlying channel and cause this method to throw java.nio.channels.ClosedByInterruptException with the interrupt status set.
  2. The socket uses the system-default socket implementation and a virtual thread is accepting a connection. In that case, interrupting the virtual thread will cause it to wakeup and close the socket. This method will then throw SocketException with the interrupt status set.
Returns:AFSocket<A>

the new Socket

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs when waiting for a connection, the socket is not bound or the socket is closed.
accept1back to summary
pack-priv AFSocket<A> accept1(boolean throwOnFail) throws IOException
addCloseableback to summary
public final void addCloseable(Closeable closeable)

Registers a Closeable that should be closed when this socket is closed.

Parameters
closeable:Closeable

The closeable.

addressFamilyback to summary
protected final AFAddressFamily<A> addressFamily()

Returns the address family supported by this implementation.

Returns:AFAddressFamily<A>

The family.

bindback to summary
public final void bind(SocketAddress endpoint) throws IOException

Overrides java.net.ServerSocket.bind.

Doc from java.net.ServerSocket.bind.

Binds the ServerSocket to a specific address (IP address and port number).

If the address is null, then the system will pick up an ephemeral port and a valid local address to bind the socket.

Parameters
endpoint:SocketAddress

The IP address and port number to bind to.

Annotations
@Override
Exceptions
IOException:
if the bind operation fails, the socket is already bound or the socket is closed.
bindback to summary
public final void bind(SocketAddress endpoint, int backlog) throws IOException

Overrides java.net.ServerSocket.bind.

Doc from java.net.ServerSocket.bind.

Binds the ServerSocket to a specific address (IP address and port number).

If the address is null, then the system will pick up an ephemeral port and a valid local address to bind the socket.

The backlog argument is the requested maximum number of pending connections on the socket. Its exact semantics are implementation specific. In particular, an implementation may impose a maximum length or may choose to ignore the parameter altogether. The value provided should be greater than 0. If it is less than or equal to 0, then an implementation specific default will be used.

Parameters
endpoint:SocketAddress

The IP address and port number to bind to.

backlog:int

requested maximum length of the queue of incoming connections.

Annotations
@SuppressWarnings:unchecked
@Override
Exceptions
IOException:
if the bind operation fails, the socket is already bound or the socket is closed.
bindHookback to summary
public final AFServerSocket<A> bindHook(SocketAddressFilter hook)

Sets the hook for any subsequent call to bind(SocketAddress) and bind(SocketAddress, int) to be the given function. The function can monitor calls or even alter the endpoint address.

Parameters
hook:SocketAddressFilter

The function that gets called for each bind call.

Returns:AFServerSocket<A>

This instance.

bindOnback to summary
protected static <A extends AFSocketAddress> AFServerSocket<A> bindOn(AFServerSocket.Constructor<A> instanceSupplier, final AFSocketAddress addr) throws IOException

Returns a new ServerSocket that is bound to the given AFSocketAddress.

Parameters
<A>
The concrete AFSocketAddress that is supported by this type.
instanceSupplier:AFServerSocket.Constructor<A>

The constructor of the concrete subclass.

addr:AFSocketAddress

The socket file to bind to.

Returns:AFServerSocket<A>

The new, bound AFServerSocket.

Exceptions
IOException:
if the operation fails.
bindOnback to summary
protected static <A extends AFSocketAddress> AFServerSocket<A> bindOn(AFServerSocket.Constructor<A> instanceSupplier, final A addr, boolean deleteOnClose) throws IOException

Returns a new ServerSocket that is bound to the given AFSocketAddress.

Parameters
<A>
The concrete AFSocketAddress that is supported by this type.
instanceSupplier:AFServerSocket.Constructor<A>

The constructor of the concrete subclass.

addr:A

The socket file to bind to.

deleteOnClose:boolean

If true, the socket file (if the address points to a file) will be deleted upon close.

Returns:AFServerSocket<A>

The new, bound AFServerSocket.

Exceptions
IOException:
if the operation fails.
boundEndpoint0back to summary
private synchronized @Nullable A boundEndpoint0()
closeback to summary
public void close() throws IOException

Overrides java.net.ServerSocket.close.

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
forceBindAddressback to summary
public final AFServerSocket<A> forceBindAddress(SocketAddress endpoint)

Forces the address to be used for any subsequent call to bind(SocketAddress) to be the given one, regardless of what'll be passed to bind(SocketAddress, int), but doesn't bind yet.

Parameters
endpoint:SocketAddress

The forced endpoint address.

Returns:AFServerSocket<A>

This AFServerSocket.

forceBindOnback to summary
protected static <A extends AFSocketAddress> AFServerSocket<A> forceBindOn(AFServerSocket.Constructor<A> instanceSupplier, final A forceAddr) throws IOException

Returns a new, unbound ServerSocket that will always bind to the given address, regardless of any socket address used in a call to bind.

Parameters
<A>
The concrete AFSocketAddress that is supported by this type.
instanceSupplier:AFServerSocket.Constructor<A>

The constructor of the concrete subclass.

forceAddr:A

The address to use.

Returns:AFServerSocket<A>

The new, yet unbound AFServerSocket.

Exceptions
IOException:
if an exception occurs.
getAFImplback to summary
pack-priv final AFSocketImpl<A> getAFImpl()
getChannelback to summary
public AFServerSocketChannel<A> getChannel()

Overrides java.net.ServerSocket.getChannel.

Doc from java.net.ServerSocket.getChannel.

Returns the unique java.nio.channels.ServerSocketChannel object associated with this socket, if any.

A server socket will have a channel if, and only if, the channel itself was created via the ServerSocketChannel.open method.

Returns:AFServerSocketChannel<A>

the server-socket channel associated with this socket, or null if this socket was not created for a channel

Annotations
@SuppressFBWarnings:EI_EXPOSE_REP
@Override
getFileDescriptorback to summary
public final FileDescriptor getFileDescriptor() throws IOException

Implements org.newsclub.net.unix.FileDescriptorAccess.getFileDescriptor.

Doc from org.newsclub.net.unix.FileDescriptorAccess.getFileDescriptor.

Returns the corresponding FileDescriptor.

Returns:FileDescriptor

The corresponding FileDescriptor.

Annotations
@Override
Exceptions
IOException:
on error.
getInetAddressback to summary
public InetAddress getInetAddress()

Overrides java.net.ServerSocket.getInetAddress.

Doc from java.net.ServerSocket.getInetAddress.

Returns the local address of this server socket.

If the socket was bound prior to being closed, then this method will continue to return the local address after the socket is closed.

Returns:InetAddress

the address to which this socket is bound, or null if the socket is unbound.

Annotations
@Override
getLocalPortback to summary
public final int getLocalPort()

Overrides java.net.ServerSocket.getLocalPort.

Doc from java.net.ServerSocket.getLocalPort.

Returns the port number on which this socket is listening.

If the socket was bound prior to being closed, then this method will continue to return the port number after the socket is closed.

Returns:int

the port number to which this socket is listening or -1 if the socket is not bound yet.

Annotations
@Override
getLocalSocketAddressback to summary
public final @Nullable A getLocalSocketAddress()

Overrides java.net.ServerSocket.getLocalSocketAddress.

Implements org.newsclub.net.unix.AFSomeSocketThing.getLocalSocketAddress.

Doc from org.newsclub.net.unix.AFSomeSocketThing.getLocalSocketAddress.

Returns the socket's local socket address, or null if unavailable or if there was a problem retrieving it.

Returns:@Nullable A

The local socket address, or null.

Annotations
@Override
@SuppressFBWarnings:EI_EXPOSE_REP
getOptionback to summary
public <T> T getOption(SocketOption<T> name) throws IOException

Overrides java.net.ServerSocket.getOption.

Doc from java.net.ServerSocket.getOption.

Returns the value of a socket option.

Parameters
<T>
The type of the socket option value
name:SocketOption<T>

The socket option

Returns:T

The value of the socket option.

Annotations
@SuppressWarnings:all, MissingOverride
Exceptions
IOException:
if an I/O error occurs, or if the socket is closed.
getReceiveBufferSizeback to summary
public synchronized int getReceiveBufferSize() throws SocketException

Overrides java.net.ServerSocket.getReceiveBufferSize.

Doc from java.net.ServerSocket.getReceiveBufferSize.

Gets the value of the SO_RCVBUF option for this ServerSocket, that is the proposed buffer size that will be used for Sockets accepted from this ServerSocket.

Note, the value actually set in the accepted socket is determined by calling Socket#getReceiveBufferSize().

Returns:int

the value of the SO_RCVBUF option for this Socket.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error, or the socket is closed.
getReuseAddressback to summary
public boolean getReuseAddress() throws SocketException

Overrides java.net.ServerSocket.getReuseAddress.

Doc from java.net.ServerSocket.getReuseAddress.

Tests if SO_REUSEADDR is enabled.

Returns:boolean

a boolean indicating whether or not SO_REUSEADDR is enabled.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error, or the socket is closed.
getSoTimeoutback to summary
public int getSoTimeout() throws IOException

Overrides java.net.ServerSocket.getSoTimeout.

Doc from java.net.ServerSocket.getSoTimeout.

Retrieve setting for SO_TIMEOUT. 0 returns implies that the option is disabled (i.e., timeout of infinity).

Returns:int

the SO_TIMEOUT value

Annotations
@Override
@SuppressWarnings:UnsynchronizedOverridesSynchronized
Exceptions
IOException:
if an I/O error occurs or the socket is closed.
isBoundback to summary
public final boolean isBound()

Overrides java.net.ServerSocket.isBound.

Doc from java.net.ServerSocket.isBound.

Returns the binding state of the ServerSocket.

If the socket was bound prior to being closed, then this method will continue to return true after the socket is closed.

Returns:boolean

true if the ServerSocket successfully bound to an address

Annotations
@Override
isClosedback to summary
public final boolean isClosed()

Overrides java.net.ServerSocket.isClosed.

Doc from java.net.ServerSocket.isClosed.

Returns the closed state of the ServerSocket.

Returns:boolean

true if the socket has been closed

Annotations
@Override
isDeleteOnCloseback to summary
public final boolean isDeleteOnClose()

Checks if this AFServerSocket's file should be removed upon close(). Deletion is not guaranteed, especially when not supported (e.g., addresses in the abstract namespace).

Returns:boolean

true if an attempt is made to delete the socket file upon close().

isLocalSocketAddressValidback to summary
public boolean isLocalSocketAddressValid()

Checks if the local socket address returned by getLocalSocketAddress() is still valid. The address is no longer valid if the server socket has been closed, null, or another server socket has been bound on that address.

Returns:boolean

true iff still valid.

isSupportedback to summary
public static boolean isSupported()

Checks whether everything is setup to support junixsocket sockets.

Returns:boolean

true if supported.

newChannelback to summary
protected abstract AFServerSocketChannel<A> newChannel()

Creates a new AFServerSocketChannel for this socket.

Returns:AFServerSocketChannel<A>

The new instance.

newImplback to summary
protected abstract AFSocketImpl<A> newImpl(FileDescriptor fdObj) throws IOException

Creates a new AFSocketImpl.

Parameters
fdObj:FileDescriptor

The file descriptor.

Returns:AFSocketImpl<A>

The new instance.

Exceptions
IOException:
on error.
newInstanceback to summary
protected static <A extends AFSocketAddress> AFServerSocket<A> newInstance(AFServerSocket.Constructor<A> instanceSupplier) throws IOException

Creates a new AFServerSocket instance, using the given subclass constructor.

Parameters
<A>
The concrete AFSocketAddress that is supported by this type.
instanceSupplier:AFServerSocket.Constructor<A>

The subclass constructor.

Returns:AFServerSocket<A>

The new instance.

Exceptions
IOException:
on error.
newInstanceback to summary
protected static <A extends AFSocketAddress> AFServerSocket<A> newInstance(AFServerSocket.Constructor<A> instanceSupplier, FileDescriptor fdObj, int localPort, int remotePort) throws IOException

Creates a new AFServerSocket instance, using the given subclass constructor.

Parameters
<A>
The concrete AFSocketAddress that is supported by this type.
instanceSupplier:AFServerSocket.Constructor<A>

The subclass constructor.

fdObj:FileDescriptor

The file descriptor.

localPort:int

The local port.

remotePort:int

The remote port.

Returns:AFServerSocket<A>

The new instance.

Exceptions
IOException:
on error.
newSocketInstanceback to summary
protected abstract AFSocket<A> newSocketInstance() throws IOException

Returns a new AFSocket instance.

Returns:AFSocket<A>

The new instance.

Exceptions
IOException:
on error.
removeCloseableback to summary
public final void removeCloseable(Closeable closeable)

Unregisters a previously registered Closeable.

Parameters
closeable:Closeable

The closeable.

setBoundEndpointback to summary
pack-priv final synchronized void setBoundEndpoint(@Nullable A addr)
setDeleteOnCloseback to summary
public final void setDeleteOnClose(boolean b)

Enables/disables deleting this AFServerSocket's file (or other resource type) upon close(). Deletion is not guaranteed, especially when not supported (e.g., addresses in the abstract namespace).

Parameters
b:boolean

Enabled if true.

setOptionback to summary
public <T> ServerSocket setOption(SocketOption<T> name, T value) throws IOException

Overrides java.net.ServerSocket.setOption.

Doc from java.net.ServerSocket.setOption.

Sets the value of a socket option.

Parameters
<T>
The type of the socket option value
name:SocketOption<T>

The socket option

value:T

The value of the socket option. A value of null may be valid for some options.

Returns:ServerSocket

this ServerSocket

Annotations
@SuppressWarnings:all, MissingOverride
Exceptions
IOException:
if an I/O error occurs, or if the socket is closed.
setPerformancePreferencesback to summary
public void setPerformancePreferences(int connectionTime, int latency, int bandwidth)

Overrides java.net.ServerSocket.setPerformancePreferences.

Doc from java.net.ServerSocket.setPerformancePreferences.

Sets performance preferences for this ServerSocket.

Sockets use the TCP/IP protocol by default. Some implementations may offer alternative protocols which have different performance characteristics than TCP/IP. This method allows the application to express its own preferences as to how these tradeoffs should be made when the implementation chooses from the available protocols.

Performance preferences are described by three integers whose values indicate the relative importance of short connection time, low latency, and high bandwidth. The absolute values of the integers are irrelevant; in order to choose a protocol the values are simply compared, with larger values indicating stronger preferences. If the application prefers short connection time over both low latency and high bandwidth, for example, then it could invoke this method with the values (1, 0, 0). If the application prefers high bandwidth above low latency, and low latency above short connection time, then it could invoke this method with the values (0, 1, 2).

Invoking this method after this socket has been bound will have no effect. This implies that in order to use this capability requires the socket to be created with the no-argument constructor.

Parameters
connectionTime:int

An int expressing the relative importance of a short connection time

latency:int

An int expressing the relative importance of low latency

bandwidth:int

An int expressing the relative importance of high bandwidth

Annotations
@Override
setReceiveBufferSizeback to summary
public synchronized void setReceiveBufferSize(int size) throws SocketException

Overrides java.net.ServerSocket.setReceiveBufferSize.

Doc from java.net.ServerSocket.setReceiveBufferSize.

Sets a default proposed value for the SO_RCVBUF option for sockets accepted from this ServerSocket. The value actually set in the accepted socket must be determined by calling Socket#getReceiveBufferSize() after the socket is returned by accept().

The value of SO_RCVBUF is used both to set the size of the internal socket receive buffer, and to set the size of the TCP receive window that is advertised to the remote peer.

It is possible to change the value subsequently, by calling Socket#setReceiveBufferSize(int). However, if the application wishes to allow a receive window larger than 64K bytes, as defined by RFC1323 then the proposed value must be set in the ServerSocket before it is bound to a local address. This implies, that the ServerSocket must be created with the no-argument constructor, then setReceiveBufferSize() must be called and lastly the ServerSocket is bound to an address by calling bind().

Failure to do this will not cause an error, and the buffer size may be set to the requested value but the TCP receive window in sockets accepted from this ServerSocket will be no larger than 64K bytes.

Parameters
size:int

the size to which to set the receive buffer size. This value must be greater than 0.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error, or the socket is closed.
setReuseAddressback to summary
public void setReuseAddress(boolean on) throws SocketException

Overrides java.net.ServerSocket.setReuseAddress.

Doc from java.net.ServerSocket.setReuseAddress.

Enable/disable the SO_REUSEADDR socket option.

When a TCP connection is closed the connection may remain in a timeout state for a period of time after the connection is closed (typically known as the TIME_WAIT state or 2MSL wait state). For applications using a well known socket address or port it may not be possible to bind a socket to the required SocketAddress if there is a connection in the timeout state involving the socket address or port.

Enabling SO_REUSEADDR prior to binding the socket using bind(SocketAddress) allows the socket to be bound even though a previous connection is in a timeout state.

When a ServerSocket is created the initial setting of SO_REUSEADDR is not defined. Applications can use getReuseAddress() to determine the initial setting of SO_REUSEADDR.

The behaviour when SO_REUSEADDR is enabled or disabled after a socket is bound (See isBound()) is not defined.

Parameters
on:boolean

whether to enable or disable the socket option

Annotations
@Override
Exceptions
SocketException:
if an error occurs enabling or disabling the SO_REUSEADDR socket option, or the socket is closed.
setShutdownOnCloseback to summary
public void setShutdownOnClose(boolean enabled)

Implements org.newsclub.net.unix.AFSomeSocketThing.setShutdownOnClose.

Doc from org.newsclub.net.unix.AFSomeSocketThing.setShutdownOnClose.

Configures whether the socket should be shutdown upon close(), which is the default.

Parameters
enabled:boolean

true if enabled.

Annotations
@Override
setSoTimeoutback to summary
public void setSoTimeout(int timeout) throws SocketException

Overrides java.net.ServerSocket.setSoTimeout.

Doc from java.net.ServerSocket.setSoTimeout.

Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a positive timeout value, a call to accept() for this ServerSocket will block for only this amount of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the ServerSocket is still valid. A timeout of zero is interpreted as an infinite timeout. The option must be enabled prior to entering the blocking operation to have effect.

Parameters
timeout:int

the specified timeout, in milliseconds

Annotations
@Override
@SuppressWarnings:UnsynchronizedOverridesSynchronized
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error, or the socket is closed.
supportedOptionsback to summary
public Set<SocketOption<?>> supportedOptions()

Overrides java.net.ServerSocket.supportedOptions.

Doc from java.net.ServerSocket.supportedOptions.

Returns a set of the socket options supported by this server socket. This method will continue to return the set of options even after the socket has been closed.

Returns:Set<SocketOption<?>>

A set of the socket options supported by this socket. This set may be empty if the socket's SocketImpl cannot be created.

Annotations
@SuppressWarnings:all
toStringback to summary
public String toString()

Overrides java.net.ServerSocket.toString.

Doc from java.net.ServerSocket.toString.

Returns the implementation address and implementation port of this socket as a String.

Returns:String

a string representation of this socket.

Annotations
@Override
org.newsclub.net.unix back to summary

public Interface AFServerSocket.Constructor<A extends AFSocketAddress>

Type Parameters
<A>
The concrete AFSocketAddress that is supported by this type.

The constructor of the concrete subclass.

Method Summary

Modifier and TypeMethod and Description
public @NonNull AFServerSocket<A>

Returns:

The new instance.
newInstance
(FileDescriptor
The file descriptor.
fd
)

Creates a new AFServerSocket instance.

Method Detail

newInstanceback to summary
public @NonNull AFServerSocket<A> newInstance(FileDescriptor fd) throws IOException

Creates a new AFServerSocket instance.

Parameters
fd:FileDescriptor

The file descriptor.

Returns:@NonNull AFServerSocket<A>

The new instance.

Exceptions
IOException:
on error.