Module org.newsclub.net.unix
Package org.newsclub.net.unix
Class AFServerSocketChannel<A extends AFSocketAddress>
java.lang.Object
java.nio.channels.spi.AbstractInterruptibleChannel
java.nio.channels.SelectableChannel
java.nio.channels.spi.AbstractSelectableChannel
java.nio.channels.ServerSocketChannel
org.newsclub.net.unix.AFServerSocketChannel<A>
- Type Parameters:
A
- The concreteAFSocketAddress
that is supported by this type.
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Channel
,InterruptibleChannel
,NetworkChannel
,AFSomeSocketChannel
,AFSomeSocketThing
,FileDescriptorAccess
- Direct Known Subclasses:
AFUNIXServerSocketChannel
public abstract class AFServerSocketChannel<A extends AFSocketAddress>
extends ServerSocketChannel
implements FileDescriptorAccess, AFSomeSocketChannel
A selectable channel for stream-oriented listening sockets.
- Author:
- Christian Kohlschütter
-
Constructor Summary
ModifierConstructorDescriptionprotected
AFServerSocketChannel
(AFServerSocket<A> socket, AFSelectorProvider<A> sp) Creates a newAFServerSocketChannel
instance. -
Method Summary
Modifier and TypeMethodDescriptionaccept()
final AFServerSocketChannel
<A> bind
(SocketAddress local, int backlog) 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.<T> T
getOption
(SocketOption<T> name) protected final void
protected final void
implConfigureBlocking
(boolean block) final boolean
Checks if thisAFServerSocketChannel
's file should be removed uponAbstractInterruptibleChannel.close()
.final boolean
Checks if the local socket address returned bygetLocalAddress()
is still valid.static ServerSocketChannel
open
(ProtocolFamily family) Opens a server-socket channel.final void
setDeleteOnClose
(boolean b) Enables/disables deleting thisAFServerSocketChannel
's file (or other resource type) uponAbstractInterruptibleChannel.close()
.<T> AFServerSocketChannel
<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 AFServerSocket
<A> socket()
final Set
<SocketOption<?>> Methods inherited from class java.nio.channels.ServerSocketChannel
bind, open, validOps
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
-
Constructor Details
-
AFServerSocketChannel
Creates a newAFServerSocketChannel
instance.- Parameters:
socket
- The correspondingServerSocket
.sp
- The correspondingSelectorProvider
.
-
-
Method Details
-
getOption
- Specified by:
getOption
in interfaceNetworkChannel
- Throws:
IOException
-
setOption
- Specified by:
setOption
in interfaceNetworkChannel
- Specified by:
setOption
in classServerSocketChannel
- Throws:
IOException
-
supportedOptions
- Specified by:
supportedOptions
in interfaceNetworkChannel
-
bind
- Specified by:
bind
in classServerSocketChannel
- Throws:
IOException
-
socket
- Specified by:
socket
in classServerSocketChannel
-
accept
- Specified by:
accept
in classServerSocketChannel
- Throws:
IOException
-
getLocalAddress
- Specified by:
getLocalAddress
in interfaceNetworkChannel
- Specified by:
getLocalAddress
in classServerSocketChannel
-
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
.
-
isLocalSocketAddressValid
public final boolean isLocalSocketAddressValid()Checks if the local socket address returned bygetLocalAddress()
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:
true
iff still valid.
-
implCloseSelectableChannel
- Specified by:
implCloseSelectableChannel
in classAbstractSelectableChannel
- Throws:
IOException
-
implConfigureBlocking
- Specified by:
implConfigureBlocking
in classAbstractSelectableChannel
- Throws:
IOException
-
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 thisAFServerSocketChannel
's file 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 thisAFServerSocketChannel
's file (or other resource type) 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 server-socket 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 toServerSocketChannel.open()
.- Parameters:
family
- The protocol family.- Returns:
- The new
ServerSocketChannel
. - Throws:
IOException
- on error.
-