< prev index next > src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java
Print this page
private static final int ST_CLOSING = 3;
private static final int ST_CLOSED = 4;
private volatile int state; // need stateLock to change
// IDs of native threads doing reads and writes, for signalling
! private long readerThread;
! private long writerThread;
// Binding
private SocketAddress localAddress;
private SocketAddress remoteAddress;
private static final int ST_CLOSING = 3;
private static final int ST_CLOSED = 4;
private volatile int state; // need stateLock to change
// IDs of native threads doing reads and writes, for signalling
! private NativeThread readerThread;
! private NativeThread writerThread;
// Binding
private SocketAddress localAddress;
private SocketAddress remoteAddress;
private void endRead(boolean blocking, boolean completed)
throws AsynchronousCloseException
{
if (blocking) {
synchronized (stateLock) {
! readerThread = 0;
if (state == ST_CLOSING) {
tryFinishClose();
}
}
// remove hook for Thread.interrupt
private void endRead(boolean blocking, boolean completed)
throws AsynchronousCloseException
{
if (blocking) {
synchronized (stateLock) {
! readerThread = null;
if (state == ST_CLOSING) {
tryFinishClose();
}
}
// remove hook for Thread.interrupt
private void endWrite(boolean blocking, boolean completed)
throws AsynchronousCloseException
{
if (blocking) {
synchronized (stateLock) {
! writerThread = 0;
if (state == ST_CLOSING) {
tryFinishClose();
}
}
// remove hook for Thread.interrupt
private void endWrite(boolean blocking, boolean completed)
throws AsynchronousCloseException
{
if (blocking) {
synchronized (stateLock) {
! writerThread = null;
if (state == ST_CLOSING) {
tryFinishClose();
}
}
// remove hook for Thread.interrupt
* Marks the end of a transfer to this channel.
* @throws AsynchronousCloseException if not completed and the channel is closed
*/
void afterTransferTo(boolean completed) throws AsynchronousCloseException {
synchronized (stateLock) {
! writerThread = 0;
if (state == ST_CLOSING) {
tryFinishClose();
}
}
writeLock.unlock();
* Marks the end of a transfer to this channel.
* @throws AsynchronousCloseException if not completed and the channel is closed
*/
void afterTransferTo(boolean completed) throws AsynchronousCloseException {
synchronized (stateLock) {
! writerThread = null;
if (state == ST_CLOSING) {
tryFinishClose();
}
}
writeLock.unlock();
* Closes the socket if there are no I/O operations in progress (or no I/O
* operations tracked), and the channel is not registered with a Selector.
*/
private boolean tryClose() throws IOException {
assert Thread.holdsLock(stateLock) && state == ST_CLOSING;
! if ((readerThread == 0) && (writerThread == 0) && !isRegistered()) {
state = ST_CLOSED;
nd.close(fd);
return true;
} else {
return false;
* Closes the socket if there are no I/O operations in progress (or no I/O
* operations tracked), and the channel is not registered with a Selector.
*/
private boolean tryClose() throws IOException {
assert Thread.holdsLock(stateLock) && state == ST_CLOSING;
! if ((readerThread == null) && (writerThread == null) && !isRegistered()) {
state = ST_CLOSED;
nd.close(fd);
return true;
} else {
return false;
ensureOpen();
if (!isConnected())
throw new NotYetConnectedException();
if (!isInputClosed) {
Net.shutdown(fd, Net.SHUT_RD);
! long reader = readerThread;
! if (NativeThread.isVirtualThread(reader)) {
- Poller.stopPoll(fdVal, Net.POLLIN);
- } else if (NativeThread.isNativeThread(reader)) {
- NativeThread.signal(reader);
}
isInputClosed = true;
}
return this;
}
ensureOpen();
if (!isConnected())
throw new NotYetConnectedException();
if (!isInputClosed) {
Net.shutdown(fd, Net.SHUT_RD);
! if (NativeThread.isVirtualThread(readerThread)) {
! Poller.stopPoll(readerThread.thread());
}
isInputClosed = true;
}
return this;
}
ensureOpen();
if (!isConnected())
throw new NotYetConnectedException();
if (!isOutputClosed) {
Net.shutdown(fd, Net.SHUT_WR);
! long writer = writerThread;
! if (NativeThread.isVirtualThread(writer)) {
- Poller.stopPoll(fdVal, Net.POLLOUT);
- } else if (NativeThread.isNativeThread(writer)) {
- NativeThread.signal(writer);
}
isOutputClosed = true;
}
return this;
}
ensureOpen();
if (!isConnected())
throw new NotYetConnectedException();
if (!isOutputClosed) {
Net.shutdown(fd, Net.SHUT_WR);
! if (NativeThread.isVirtualThread(writerThread)) {
! Poller.stopPoll(writerThread.thread());
}
isOutputClosed = true;
}
return this;
}
< prev index next >