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

pack-priv Class SourceChannelImpl

extends SourceChannel
implements SelChImpl
Class Inheritance
All Implemented Interfaces
sun.nio.ch.SelChImpl, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable
Imports
java.io.FileDescriptor, .IOException, java.nio.ByteBuffer, java.nio.channels.AsynchronousCloseException, .ClosedChannelException, .NotYetConnectedException, .Pipe, .SelectionKey, java.nio.channels.spi.SelectorProvider, java.util.Objects, java.util.concurrent.locks.ReentrantLock

Field Summary

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

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private void
beginRead(boolean blocking)

Marks the beginning of a read operation that might block.

private void
configureSocketNonBlockingIfVirtualThread()

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

private void
endRead(boolean blocking, boolean completed)

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

private void
ensureOpen()

Checks that the channel is open.

public FileDescriptor
public 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.

public void
public int
read(ByteBuffer dst)

Implements java.nio.channels.ReadableByteChannel.read.

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

public long
read(ByteBuffer[] dsts, int offset, int length)

Implements java.nio.channels.ScatteringByteChannel.read.

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

public long
read(ByteBuffer[] dsts)

Implements java.nio.channels.ScatteringByteChannel.read.

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

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 event set

public boolean
translateReadyOps(int ops, int initialOps, SelectionKeyImpl ski)

private boolean
tryClose()

Closes the read end of the pipe if there are no read operation in progress and the channel is not registered with a Selector.

private void
tryFinishClose()

Invokes tryClose to attempt to close the read end of the pipe.

Inherited from java.nio.channels.Pipe.SourceChannel:
validOps

Field Detail

fdback to summary
private final FileDescriptor fd
fdValback to summary
private final int fdVal
forcedNonBlockingback to summary
private volatile boolean forcedNonBlocking
ndback to summary
private static final NativeDispatcher nd
readerThreadback to summary
private Thread readerThread
readLockback to summary
private final ReentrantLock readLock
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

Constructor Detail

SourceChannelImplback to summary
pack-priv SourceChannelImpl(SelectorProvider sp, FileDescriptor fd) throws IOException

Method Detail

beginReadback to summary
private void beginRead(boolean blocking) throws ClosedChannelException

Marks the beginning of a read operation that might block.

Exceptions
ClosedChannelException:
if the channel is closed
NotYetConnectedException:
if the channel is not yet connected
configureSocketNonBlockingIfVirtualThreadback to summary
private void configureSocketNonBlockingIfVirtualThread() throws IOException

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

endReadback to summary
private void endRead(boolean blocking, boolean completed) throws AsynchronousCloseException

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

Exceptions
AsynchronousCloseException:
if the channel was closed due to this thread being interrupted on a blocking read operation.
ensureOpenback to summary
private void ensureOpen() throws ClosedChannelException

Checks that the channel is open.

Exceptions
ClosedChannelException:
if channel is closed (or closing)
getFDback to summary
public FileDescriptor getFD()

Implements sun.nio.ch.SelChImpl.getFD.

getFDValback to summary
public int getFDVal()

Implements sun.nio.ch.SelChImpl.getFDVal.

implCloseBlockingModeback to summary
private void implCloseBlockingMode() throws IOException

Closes this channel when configured in blocking mode. If there is a read operation in progress then the read-end of the pipe is pre-closed and the reader is signalled, in which case the final close is deferred until the reader 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
killback to summary
public void kill()

Implements sun.nio.ch.SelChImpl.kill.

Annotations
@Override
readback to summary
public int read(ByteBuffer dst) throws IOException

Implements java.nio.channels.ReadableByteChannel.read.

Doc from java.nio.channels.ReadableByteChannel.read.

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

An attempt is made to read up to r bytes from the channel, where r is the number of bytes remaining in the buffer, that is, dst.remaining(), at the moment this method is invoked.

Suppose that a byte sequence of length n is read, where 0 <= n <= r. This byte sequence will be transferred into the buffer so that the first byte in the sequence is at index p and the last byte is at index p + n - 1, where p is the buffer's position at the moment this method is invoked. Upon return the buffer's position will be equal to p + n; its limit will not have changed.

A read operation might not fill the buffer, and in fact it might not read any bytes at all. Whether or not it does so depends upon the nature and state of the channel. A socket channel in non-blocking mode, for example, cannot read any more bytes than are immediately available from the socket's input buffer; similarly, a file channel cannot read any more bytes than remain in the file. It is guaranteed, however, that if a channel is in blocking mode and there is at least one byte remaining in the buffer then this method will block until at least one byte is read.

This method may be invoked at any time. If another thread has already initiated a read operation upon this channel, however, then an invocation of this method will block until the first operation is complete.

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
readback to summary
public long read(ByteBuffer[] dsts, int offset, int length) throws IOException

Implements java.nio.channels.ScatteringByteChannel.read.

Doc from java.nio.channels.ScatteringByteChannel.read.

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

An invocation of this method attempts to read up to r bytes from this channel, where r is the total number of bytes remaining in the specified subsequence of the given buffer array, that is,

dsts[offset].remaining() + dsts[offset+1].remaining() + ... + dsts[offset+length-1].remaining()
dsts[offset].remaining()
    + dsts[offset+1].remaining()
    + ... + dsts[offset+length-1].remaining()
at the moment that this method is invoked.

Suppose that a byte sequence of length n is read, where 0 <= n <= r. Up to the first dsts[offset].remaining() bytes of this sequence are transferred into buffer dsts[offset], up to the next dsts[offset+1].remaining() bytes are transferred into buffer dsts[offset+1], and so forth, until the entire byte sequence is transferred into the given buffers. As many bytes as possible are transferred into each buffer, hence the final position of each updated buffer, except the last updated buffer, is guaranteed to be equal to that buffer's limit.

This method may be invoked at any time. If another thread has already initiated a read operation upon this channel, however, then an invocation of this method will block until the first operation is complete.

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
readback to summary
public long read(ByteBuffer[] dsts) throws IOException

Implements java.nio.channels.ScatteringByteChannel.read.

Doc from java.nio.channels.ScatteringByteChannel.read.

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

An invocation of this method of the form c.read(dsts) behaves in exactly the same manner as the invocation

c.read(dsts, 0, dsts.length);
c.read(dsts, 0, dsts.length);
Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
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.

Doc from sun.nio.ch.SelChImpl.translateInterestOps.

Translates an interest operation set into a native event set

translateReadyOpsback to summary
public boolean translateReadyOps(int ops, int initialOps, SelectionKeyImpl ski)
tryCloseback to summary
private boolean tryClose() throws IOException

Closes the read end of the pipe if there are no read operation in progress and the channel is not registered with a Selector.

tryFinishCloseback to summary
private void tryFinishClose()

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