Top Description Inners Fields Constructors Methods
sun.nio.ch

pack-priv Class SocketChannelImpl

extends SocketChannel
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.InheritedSocketChannelImpl
Imports
java.io.FileDescriptor, .IOException, java.net.InetAddress, .Inet4Address, .InetSocketAddress, .ProtocolFamily, .Socket, .SocketAddress, .SocketException, .SocketOption, .SocketTimeoutException, .StandardSocketOptions, java.nio.ByteBuffer, java.nio.channels.AlreadyBoundException, .AlreadyConnectedException, .AsynchronousCloseException, .ClosedChannelException, .ConnectionPendingException, .IllegalBlockingModeException, .NoConnectionPendingException, .NotYetConnectedException, .SelectionKey, .SocketChannel, java.nio.channels.spi.SelectorProvider, java.nio.file.Path, java.util.Collections, .HashSet, .Set, .Objects, java.util.concurrent.locks.ReentrantLock, jdk.internal.event.SocketReadEvent, .SocketWriteEvent, sun.net.ConnectionResetException, .NetHooks, sun.net.ext.ExtendedSocketOptions, sun.net.util.SocketExceptions

An implementation of SocketChannels

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

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

Constructor Summary

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

Method Summary

Modifier and TypeMethod and Description
pack-priv void
afterTransferTo(boolean completed)

Marks the end of a transfer to this channel.

pack-priv int
available()

Return the number of bytes in the socket input buffer.

pack-priv void
beforeTransferTo()

Marks the beginning of a transfer to this channel.

private void
beginConnect(boolean
true if configured blocking
blocking
,
SocketAddress
the remote address
sa
)

Marks the beginning of a connect operation that might block.

private void
beginFinishConnect(boolean blocking)

Marks the beginning of a finishConnect operation that might block.

private void
beginRead(boolean blocking)

Marks the beginning of a read operation that might block.

private void
beginWrite(boolean blocking)

Marks the beginning of a write operation that might block.

public SocketChannel
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.SocketChannel.bind.

Implements java.nio.channels.NetworkChannel.bind.

Binds the channel's socket to a local address.

pack-priv void
blockingConnect(SocketAddress remote, long nanos)

Attempts to establish a connection to the given socket address with a timeout.

pack-priv int
blockingRead(byte[] b, int off, int len, long nanos)

Reads bytes from the socket into the given byte array.

pack-priv void
blockingWriteFully(byte[] b, int off, int len)

Writes a sequence of bytes to the socket from the given byte array.

private SocketAddress
checkRemote(SocketAddress sa)

Checks the remote address to which this channel is to be connected.

private void
configureSocketNonBlockingIfVirtualThread()

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

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

Implements abstract java.nio.channels.SocketChannel.connect.

Connects this channel's socket.

private void
endConnect(boolean blocking, boolean completed)

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

private void
endFinishConnect(boolean blocking, boolean completed)

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

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
ensureOpen()

Checks that the channel is open.

private void
ensureOpenAndConnected()

Checks that the channel is open and connected.

public boolean
finishConnect()

Implements abstract java.nio.channels.SocketChannel.finishConnect.

Finishes the process of connecting a socket channel.

private boolean
finishTimedConnect(long nanos)

Waits for a connection attempt to finish with a timeout

public FileDescriptor
public int
public SocketAddress
getLocalAddress()

Implements abstract java.nio.channels.SocketChannel.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.SocketChannel.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 int
private long
implRead(ByteBuffer[] dsts, int offset, int length)

private int
private long
implWrite(ByteBuffer[] srcs, int offset, int length)

public boolean
isConnected()

Implements abstract java.nio.channels.SocketChannel.isConnected.

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

public boolean
isConnectionPending()

Implements abstract java.nio.channels.SocketChannel.isConnectionPending.

Tells whether or not a connection operation is in progress on this channel.

pack-priv boolean
pack-priv boolean
isNetSocket()

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

pack-priv boolean
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)

Adjust the blocking mode while holding readLock or writeLock.

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

Implements abstract java.nio.channels.SocketChannel.read.

Implements java.nio.channels.ReadableByteChannel.read.

Reads a sequence of bytes from this channel into the given buffer.

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.SocketChannel.read.

Implements java.nio.channels.ScatteringByteChannel.read.

Reads a sequence of bytes from this channel into a subsequence of the given buffers.

pack-priv SocketAddress
remoteAddress()

Returns the remote address, or null if not connected

pack-priv int
sendOutOfBandData(byte b)

Writes a byte of out of band data.

public <T> SocketChannel
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.SocketChannel.setOption.

Implements java.nio.channels.NetworkChannel.setOption.

Sets the value of a socket option.

public SocketChannel
shutdownInput()

Implements abstract java.nio.channels.SocketChannel.shutdownInput.

Shutdown the connection for reading without closing the channel.

public SocketChannel
shutdownOutput()

Implements abstract java.nio.channels.SocketChannel.shutdownOutput.

Shutdown the connection for writing without closing the channel.

public Socket
socket()

Implements abstract java.nio.channels.SocketChannel.socket.

Retrieves a 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.

private void
private int
timedRead(byte[] b, int off, int len, long nanos)

Reads bytes from the socket into the given byte array with a timeout.

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 ops into a ready operation ops

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.

private int
tryRead(byte[] b, int off, int len)

Attempts to read bytes from the socket into the given byte array.

private int
tryWrite(byte[] b, int off, int len)

Attempts to write a sequence of bytes to the socket from the given byte array.

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

Implements abstract java.nio.channels.SocketChannel.write.

Implements java.nio.channels.WritableByteChannel.write.

Writes a sequence of bytes to this channel from the given buffer.

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.SocketChannel.write.

Implements java.nio.channels.GatheringByteChannel.write.

Writes a sequence of bytes to this channel from a subsequence of the given buffers.

Inherited from java.nio.channels.SocketChannel:
openopenopenreadvalidOpswrite