APIdia Launch Partner
Top Description Inners Fields Constructors Methods
sun.nio.ch

pack-priv Class ServerSocketChannelImpl

extends ServerSocketChannel
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.InheritedServerSocketChannelImpl
Imports
java.io.FileDescriptor, .IOException, java.net.BindException, .InetSocketAddress, .ProtocolFamily, .ServerSocket, .SocketAddress, .SocketOption, .SocketTimeoutException, .StandardSocketOptions, .UnixDomainSocketAddress, java.nio.channels.AlreadyBoundException, .AsynchronousCloseException, .ClosedChannelException, .IllegalBlockingModeException, .NotYetBoundException, .SelectionKey, .ServerSocketChannel, .SocketChannel, java.nio.channels.spi.SelectorProvider, java.nio.file.Path, java.util.Collections, .HashSet, .Set, .Objects, java.util.concurrent.locks.ReentrantLock, sun.net.ext.ExtendedSocketOptions

An implementation of ServerSocketChannels

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final ReentrantLock
private final ProtocolFamily
private final FileDescriptor
private final int
private volatile boolean
private boolean
private SocketAddress
private static final NativeDispatcher
private ServerSocket
private static final int
private static final int
private static final int
private int
private final Object
private Thread

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv
pack-priv

Method Summary

Modifier and TypeMethod and Description
public SocketChannel
accept()

Implements abstract java.nio.channels.ServerSocketChannel.accept.

Accepts a connection made to this channel's socket.

private void
begin(boolean blocking)

Marks the beginning of an I/O operation that might block.

public ServerSocketChannel
bind(SocketAddress local, int backlog)

Implements abstract java.nio.channels.ServerSocketChannel.bind.

Binds the channel's socket to a local address and configures the socket to listen for connections.

pack-priv SocketChannel
blockingAccept(long
the timeout, in nanoseconds
nanos
)

Accepts a new connection with a given timeout.

private void
configureSocketNonBlockingIfVirtualThread()

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

private void
end(boolean blocking, boolean completed)

Marks the end of an I/O operation that may have blocked.

private void
private SocketChannel
public FileDescriptor
public int
public SocketAddress
getLocalAddress()

Implements abstract java.nio.channels.ServerSocketChannel.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> name)

Implements java.nio.channels.NetworkChannel.getOption.

Returns the value of a socket option.

private int
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 block)

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

Adjusts this channel's blocking mode.

pack-priv boolean
isBound()

Returns true if channel's socket is bound

private boolean
isNetSocket()

Returns true if this channel is to a INET or INET6 socket.

pack-priv boolean
isUnixSocket()

Returns true if this channel is to a UNIX socket.

public void
pack-priv SocketAddress
localAddress()

Returns the local address, or null if not bound

private void
lockedConfigureBlocking(boolean block)

Adjusts the blocking mode.

private SocketAddress
netBind(SocketAddress local, int backlog)

public <T> ServerSocketChannel
setOption(SocketOption<T> name, T value)

Implements abstract java.nio.channels.ServerSocketChannel.setOption.

Implements java.nio.channels.NetworkChannel.setOption.

Sets the value of a socket option.

public ServerSocket
socket()

Implements abstract java.nio.channels.ServerSocketChannel.socket.

Retrieves a server socket associated with this channel.

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

Implements java.nio.channels.NetworkChannel.supportedOptions.

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

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

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 boolean
tryClose()

Closes the socket if there are no accept 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.

private SocketAddress
unixBind(SocketAddress local, int backlog)

Inherited from java.nio.channels.ServerSocketChannel:
bindopenopenvalidOps

Field Detail

acceptLockback to summary
private final ReentrantLock acceptLock
familyback to summary
private final ProtocolFamily family
fdback to summary
private final FileDescriptor fd
fdValback to summary
private final int fdVal
forcedNonBlockingback to summary
private volatile boolean forcedNonBlocking
isReuseAddressback to summary
private boolean isReuseAddress
localAddressback to summary
private SocketAddress localAddress
ndback to summary
private static final NativeDispatcher nd
socketback to summary
private ServerSocket socket
ST_CLOSEDback to summary
private static final int ST_CLOSED
ST_CLOSINGback to summary
private static final int ST_CLOSING
ST_INUSEback to summary
private static final int ST_INUSE
stateback to summary
private int state
stateLockback to summary
private final Object stateLock
threadback to summary
private Thread thread

Constructor Detail

ServerSocketChannelImplback to summary
pack-priv ServerSocketChannelImpl(SelectorProvider sp) throws IOException
ServerSocketChannelImplback to summary
pack-priv ServerSocketChannelImpl(SelectorProvider sp, ProtocolFamily family) throws IOException
ServerSocketChannelImplback to summary
pack-priv ServerSocketChannelImpl(SelectorProvider sp, ProtocolFamily family, FileDescriptor fd, boolean bound) throws IOException

Method Detail

acceptback to summary
public SocketChannel accept() throws IOException

Implements abstract java.nio.channels.ServerSocketChannel.accept.

Doc from java.nio.channels.ServerSocketChannel.accept.

Accepts a connection made to this channel's socket.

If this channel is in non-blocking mode then this method will immediately return null if there are no pending connections. Otherwise it will block indefinitely until a new connection is available or an I/O error occurs.

The socket channel returned by this method, if any, will be in blocking mode regardless of the blocking mode of this channel.

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
beginback to summary
private void begin(boolean blocking) throws ClosedChannelException

Marks the beginning of an I/O operation that might block.

Exceptions
ClosedChannelException:
if the channel is closed
NotYetBoundException:
if the channel's socket has not been bound yet
bindback to summary
public ServerSocketChannel bind(SocketAddress local, int backlog) throws IOException

Implements abstract java.nio.channels.ServerSocketChannel.bind.

Doc from java.nio.channels.ServerSocketChannel.bind.

Binds the channel's socket to a local address and configures the socket to listen for connections.

This method is used to establish an association between the socket and a local address. For Internet protocol sockets, once an association is established then the socket remains bound until the channel is closed.

The backlog parameter is the 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. If the backlog parameter has the value 0, or a negative value, then an implementation specific default is used.

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
blockingAcceptback to summary
pack-priv SocketChannel blockingAccept(long nanos) throws IOException

Accepts a new connection with a given timeout. This method requires the channel to be configured in blocking mode.

API Note

This method is for use by the socket adaptor.

Parameters
nanos:long

the timeout, in nanoseconds

Exceptions
IllegalBlockingModeException:
if the channel is configured non-blocking
SocketTimeoutException:
if the timeout expires
configureSocketNonBlockingIfVirtualThreadback to summary
private void configureSocketNonBlockingIfVirtualThread() throws IOException

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

endback to summary
private void end(boolean blocking, boolean completed) throws AsynchronousCloseException

Marks the end of an I/O operation that may have blocked.

Exceptions
AsynchronousCloseException:
if the channel was closed due to this thread being interrupted on a blocking I/O operation.
ensureOpenback to summary
private void ensureOpen() throws ClosedChannelException
finishAcceptback to summary
private SocketChannel finishAccept(FileDescriptor newfd, SocketAddress sa) throws IOException
getFDback to summary
public FileDescriptor getFD()

Implements sun.nio.ch.SelChImpl.getFD.

getFDValback to summary
public int getFDVal()

Implements sun.nio.ch.SelChImpl.getFDVal.

getLocalAddressback to summary
public SocketAddress getLocalAddress() throws IOException

Implements abstract java.nio.channels.ServerSocketChannel.getLocalAddress.

Implements java.nio.channels.NetworkChannel.getLocalAddress.

Doc from java.nio.channels.ServerSocketChannel.getLocalAddress.

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

Where the channel is bound to an Internet Protocol socket address then the return value from this method is of type java.net.InetSocketAddress.

Where the channel is bound to a Unix Domain socket address, the socket address is a UnixDomainSocketAddress.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
getOptionback to summary
public <T> T getOption(SocketOption<T> name) throws IOException

Implements java.nio.channels.NetworkChannel.getOption.

Doc from java.nio.channels.NetworkChannel.getOption.

Returns the value of a socket option.

Annotations
@Override
@SuppressWarnings:unchecked
Exceptions
IOException:
If an I/O error occurs
implAcceptback to summary
private int implAccept(FileDescriptor fd, FileDescriptor newfd, SocketAddress[] saa) throws IOException
implCloseBlockingModeback to summary
private void implCloseBlockingMode() throws IOException

Closes this channel when configured in blocking mode. If there is an accept in progress then the socket is pre-closed and the accept thread is signalled, in which case the final close is deferred until the accept aborts.

implCloseNonBlockingModeback to summary
private void implCloseNonBlockingMode() throws IOException

Closes this channel when configured in non-blocking mode. If the channel is registered with a Selector then the close is deferred until the channel is flushed from all Selectors.

implCloseSelectableChannelback to summary
protected void implCloseSelectableChannel() throws IOException

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

Invoked by implCloseChannel to close the channel.

Annotations
@Override
Exceptions
IOException:

Doc from java.nio.channels.spi.AbstractSelectableChannel.implCloseSelectableChannel.

If an I/O error occurs

implConfigureBlockingback to summary
protected void implConfigureBlocking(boolean block) throws IOException

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

Doc from java.nio.channels.spi.AbstractSelectableChannel.implConfigureBlocking.

Adjusts this channel's blocking mode.

This method is invoked by the configureBlocking method in order to perform the actual work of changing the blocking mode. This method is only invoked if the new mode is different from the current mode.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
isBoundback to summary
pack-priv boolean isBound()

Returns true if channel's socket is bound

isNetSocketback to summary
private boolean isNetSocket()

Returns true if this channel is to a INET or INET6 socket.

isUnixSocketback to summary
pack-priv boolean isUnixSocket()

Returns true if this channel is to a UNIX socket.

killback to summary
public void kill()

Implements sun.nio.ch.SelChImpl.kill.

Annotations
@Override
localAddressback to summary
pack-priv SocketAddress localAddress()

Returns the local address, or null if not bound

lockedConfigureBlockingback to summary
private void lockedConfigureBlocking(boolean block) throws IOException

Adjusts the blocking mode.

netBindback to summary
private SocketAddress netBind(SocketAddress local, int backlog) throws IOException
setOptionback to summary
public <T> ServerSocketChannel setOption(SocketOption<T> name, T value) throws IOException

Implements abstract java.nio.channels.ServerSocketChannel.setOption.

Implements java.nio.channels.NetworkChannel.setOption.

Doc from java.nio.channels.NetworkChannel.setOption.

Sets the value of a socket option.

Annotations
@Override
Exceptions
IOException:

Doc from java.nio.channels.ServerSocketChannel.setOption.

If an I/O error occurs

socketback to summary
public ServerSocket socket()

Implements abstract java.nio.channels.ServerSocketChannel.socket.

Doc from java.nio.channels.ServerSocketChannel.socket.

Retrieves a server socket associated with this channel.

The returned object will not declare any public methods that are not declared in the java.net.ServerSocket class.

Annotations
@Override
supportedOptionsback to summary
public final Set<SocketOption<?>> supportedOptions()

Implements java.nio.channels.NetworkChannel.supportedOptions.

Doc from java.nio.channels.NetworkChannel.supportedOptions.

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

This method will continue to return the set of options even after the channel has been closed.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

translateAndSetReadyOpsback to summary
public boolean translateAndSetReadyOps(int ops, SelectionKeyImpl ski)

Implements sun.nio.ch.SelChImpl.translateAndSetReadyOps.

Doc from sun.nio.ch.SelChImpl.translateAndSetReadyOps.

Sets the specified ops if present in interestOps. The specified ops are turned on, and all other ops are turned off.

translateAndUpdateReadyOpsback to summary
public boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl ski)

Implements sun.nio.ch.SelChImpl.translateAndUpdateReadyOps.

Doc from sun.nio.ch.SelChImpl.translateAndUpdateReadyOps.

Adds the specified ops if present in interestOps. The specified ops are turned on without affecting the other ops.

translateInterestOpsback to summary
public int translateInterestOps(int ops)

Implements sun.nio.ch.SelChImpl.translateInterestOps.

Translates an interest operation set into a native poll event set

translateReadyOpsback to summary
public boolean translateReadyOps(int ops, int initialOps, SelectionKeyImpl ski)

Translates native poll revent set into a ready operation set

tryCloseback to summary
private boolean tryClose() throws IOException

Closes the socket if there are no accept in progress and the channel is not registered with a Selector.

tryFinishCloseback to summary
private void tryFinishClose()

Invokes tryClose to attempt to close the socket. This method is used for deferred closing by I/O and Selector operations.

tryLockedConfigureBlockingback to summary
private boolean tryLockedConfigureBlocking(boolean block) throws IOException

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

Returns:boolean

true if the blocking mode was adjusted

unixBindback to summary
private SocketAddress unixBind(SocketAddress local, int backlog) throws IOException
sun.nio.ch back to summary

private Class ServerSocketChannelImpl.DefaultOptionsHolder

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv static final Set<SocketOption<?>>
pack-priv static final Set<SocketOption<?>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static Set<SocketOption<?>>
private static Set<SocketOption<?>>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

defaultInetOptionsback to summary
pack-priv static final Set<SocketOption<?>> defaultInetOptions
defaultUnixDomainOptionsback to summary
pack-priv static final Set<SocketOption<?>> defaultUnixDomainOptions

Constructor Detail

DefaultOptionsHolderback to summary
private DefaultOptionsHolder()

Method Detail

defaultInetOptionsback to summary
private static Set<SocketOption<?>> defaultInetOptions()
defaultUnixDomainOptionsback to summary
private static Set<SocketOption<?>> defaultUnixDomainOptions()