< prev index next > src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java
Print this page
private static final int ST_CONNECTED = 2;
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;
+ // Threads doing reads and writes, for signalling
+ private Thread readerThread;
+ private Thread writerThread;
// Binding
private SocketAddress localAddress;
private SocketAddress remoteAddress;
begin();
synchronized (stateLock) {
ensureOpen();
// record thread so it can be signalled if needed
- readerThread = NativeThread.current();
+ readerThread = NativeThread.threadToSignal();
}
}
}
/**
private void endRead(boolean blocking, boolean completed)
throws AsynchronousCloseException
{
if (blocking) {
synchronized (stateLock) {
- readerThread = 0;
+ readerThread = null;
if (state == ST_CLOSING) {
tryFinishClose();
}
}
// remove hook for Thread.interrupt
synchronized (stateLock) {
ensureOpen();
if (isOutputClosed)
throw new ClosedChannelException();
// record thread so it can be signalled if needed
- writerThread = NativeThread.current();
+ writerThread = NativeThread.threadToSignal();
}
}
}
/**
private void endWrite(boolean blocking, boolean completed)
throws AsynchronousCloseException
{
if (blocking) {
synchronized (stateLock) {
- writerThread = 0;
+ writerThread = null;
if (state == ST_CLOSING) {
tryFinishClose();
}
}
// remove hook for Thread.interrupt
try {
synchronized (stateLock) {
ensureOpenAndConnected();
if (isOutputClosed)
throw new ClosedChannelException();
- writerThread = NativeThread.current();
+ writerThread = NativeThread.threadToSignal();
completed = true;
}
} finally {
if (!completed) {
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 = 0;
+ writerThread = null;
if (state == ST_CLOSING) {
tryFinishClose();
}
}
writeLock.unlock();
}
remoteAddress = sa;
if (blocking) {
// record thread so it can be signalled if needed
- readerThread = NativeThread.current();
+ readerThread = NativeThread.threadToSignal();
}
}
}
/**
ensureOpen();
if (state != ST_CONNECTIONPENDING)
throw new NoConnectionPendingException();
if (blocking) {
// record thread so it can be signalled if needed
- readerThread = NativeThread.current();
+ readerThread = NativeThread.threadToSignal();
}
}
}
/**
* 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()) {
+ 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);
+ if (readerThread != null && readerThread.isVirtual()) {
+ Poller.stopPoll(readerThread);
}
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);
+ if (writerThread != null && writerThread.isVirtual()) {
+ Poller.stopPoll(writerThread);
}
isOutputClosed = true;
}
return this;
}
< prev index next >