< prev index next > src/java.base/share/classes/sun/nio/ch/DatagramChannelImpl.java
Print this page
private static final int ST_CONNECTED = 1;
private static final int ST_CLOSING = 2;
private static final int ST_CLOSED = 3;
private int state;
! // IDs of native threads doing reads and writes, for signalling
! private long readerThread;
! private long writerThread;
// Local and remote (connected) address
private InetSocketAddress localAddress;
private InetSocketAddress remoteAddress;
private static final int ST_CONNECTED = 1;
private static final int ST_CLOSING = 2;
private static final int ST_CLOSED = 3;
private int state;
! // Threads doing reads and writes, for signalling
! private Thread readerThread;
! private Thread writerThread;
// Local and remote (connected) address
private InetSocketAddress localAddress;
private InetSocketAddress remoteAddress;
if ((remote == null) && mustBeConnected)
throw new NotYetConnectedException();
if (localAddress == null)
bindInternal(null);
if (blocking)
! readerThread = NativeThread.current();
}
return remote;
}
/**
if ((remote == null) && mustBeConnected)
throw new NotYetConnectedException();
if (localAddress == null)
bindInternal(null);
if (blocking)
! readerThread = NativeThread.threadToSignal();
}
return remote;
}
/**
private void endRead(boolean blocking, boolean completed)
throws AsynchronousCloseException
{
if (blocking) {
synchronized (stateLock) {
! readerThread = 0;
if (state == ST_CLOSING) {
tryFinishClose();
}
}
if (interruptible) {
private void endRead(boolean blocking, boolean completed)
throws AsynchronousCloseException
{
if (blocking) {
synchronized (stateLock) {
! readerThread = null;
if (state == ST_CLOSING) {
tryFinishClose();
}
}
if (interruptible) {
if ((remote == null) && mustBeConnected)
throw new NotYetConnectedException();
if (localAddress == null)
bindInternal(null);
if (blocking)
! writerThread = NativeThread.current();
}
return remote;
}
/**
if ((remote == null) && mustBeConnected)
throw new NotYetConnectedException();
if (localAddress == null)
bindInternal(null);
if (blocking)
! writerThread = NativeThread.threadToSignal();
}
return remote;
}
/**
private void endWrite(boolean blocking, boolean completed)
throws AsynchronousCloseException
{
if (blocking) {
synchronized (stateLock) {
! writerThread = 0;
if (state == ST_CLOSING) {
tryFinishClose();
}
}
private void endWrite(boolean blocking, boolean completed)
throws AsynchronousCloseException
{
if (blocking) {
synchronized (stateLock) {
! writerThread = null;
if (state == ST_CLOSING) {
tryFinishClose();
}
}
* Closes the socket if there are no I/O operations in progress 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;
try {
// close socket
cleaner.clean();
} catch (UncheckedIOException ioe) {
* Closes the socket if there are no I/O operations in progress 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;
try {
// close socket
cleaner.clean();
} catch (UncheckedIOException ioe) {
< prev index next >