< prev index next > src/java.base/share/classes/sun/nio/ch/ServerSocketChannelImpl.java
Print this page
private static final int ST_INUSE = 0;
private static final int ST_CLOSING = 1;
private static final int ST_CLOSED = 2;
private int state;
! // ID of native thread currently blocked in this channel, for signalling
! private long thread;
// Binding
private SocketAddress localAddress; // null => unbound
// set true when exclusive binding is on and SO_REUSEADDR is emulated
private static final int ST_INUSE = 0;
private static final int ST_CLOSING = 1;
private static final int ST_CLOSED = 2;
private int state;
! // Thread currently blocked in this channel, for signalling
! private Thread thread;
// Binding
private SocketAddress localAddress; // null => unbound
// set true when exclusive binding is on and SO_REUSEADDR is emulated
synchronized (stateLock) {
ensureOpen();
if (localAddress == null)
throw new NotYetBoundException();
if (blocking)
! thread = NativeThread.current();
}
}
/**
* Marks the end of an I/O operation that may have blocked.
synchronized (stateLock) {
ensureOpen();
if (localAddress == null)
throw new NotYetBoundException();
if (blocking)
! thread = NativeThread.threadToSignal();
}
}
/**
* Marks the end of an I/O operation that may have blocked.
private void end(boolean blocking, boolean completed)
throws AsynchronousCloseException
{
if (blocking) {
synchronized (stateLock) {
! thread = 0;
if (state == ST_CLOSING) {
tryFinishClose();
}
}
end(completed);
private void end(boolean blocking, boolean completed)
throws AsynchronousCloseException
{
if (blocking) {
synchronized (stateLock) {
! thread = null;
if (state == ST_CLOSING) {
tryFinishClose();
}
}
end(completed);
* Closes the socket if there are no accept in progress and the channel is
* not registered with a Selector.
*/
private boolean tryClose() throws IOException {
assert Thread.holdsLock(stateLock) && state == ST_CLOSING;
! if ((thread == 0) && !isRegistered()) {
state = ST_CLOSED;
nd.close(fd);
return true;
} else {
return false;
* Closes the socket if there are no accept in progress and the channel is
* not registered with a Selector.
*/
private boolean tryClose() throws IOException {
assert Thread.holdsLock(stateLock) && state == ST_CLOSING;
! if ((thread == null) && !isRegistered()) {
state = ST_CLOSED;
nd.close(fd);
return true;
} else {
return false;
private void implCloseBlockingMode() throws IOException {
synchronized (stateLock) {
assert state < ST_CLOSING;
state = ST_CLOSING;
if (!tryClose()) {
! nd.preClose(fd, thread, 0);
}
}
}
/**
private void implCloseBlockingMode() throws IOException {
synchronized (stateLock) {
assert state < ST_CLOSING;
state = ST_CLOSING;
if (!tryClose()) {
! nd.preClose(fd, thread, null);
}
}
}
/**
< prev index next >