< prev index next >
src/java.base/share/classes/sun/nio/ch/ServerSocketChannelImpl.java
Print this page
*** 52,124 ****
/**
* An implementation of ServerSocketChannels
*/
! class ServerSocketChannelImpl
extends ServerSocketChannel
implements SelChImpl
{
// Used to make native close and configure calls
! private static NativeDispatcher nd;
// Our file descriptor
! private final FileDescriptor fd;
! private final int fdVal;
// Lock held by thread currently blocked on this channel
! private final ReentrantLock acceptLock = new ReentrantLock();
// Lock held by any thread that modifies the state fields declared below
// DO NOT invoke a blocking I/O operation while holding this lock!
! private final Object stateLock = new Object();
// -- The following fields are protected by stateLock
// Channel state, increases monotonically
! private static final int ST_INUSE = 0;
! private static final int ST_CLOSING = 1;
! private static final int ST_KILLPENDING = 2;
! private static final int ST_KILLED = 3;
! private int state;
// ID of native thread currently blocked in this channel, for signalling
! private long thread;
// Binding
! private InetSocketAddress localAddress; // null => unbound
// set true when exclusive binding is on and SO_REUSEADDR is emulated
! private boolean isReuseAddress;
// Our socket adaptor, if any
! private ServerSocket socket;
// -- End of fields protected by stateLock
! ServerSocketChannelImpl(SelectorProvider sp) throws IOException {
super(sp);
! this.fd = Net.serverSocket(true);
this.fdVal = IOUtil.fdVal(fd);
}
! ServerSocketChannelImpl(SelectorProvider sp, FileDescriptor fd, boolean bound)
throws IOException
{
super(sp);
this.fd = fd;
this.fdVal = IOUtil.fdVal(fd);
if (bound) {
synchronized (stateLock) {
! localAddress = Net.localAddress(fd);
}
}
}
// @throws ClosedChannelException if channel is closed
! private void ensureOpen() throws ClosedChannelException {
if (!isOpen())
throw new ClosedChannelException();
}
@Override
--- 52,133 ----
/**
* An implementation of ServerSocketChannels
*/
! public class ServerSocketChannelImpl
extends ServerSocketChannel
implements SelChImpl
{
// Used to make native close and configure calls
! protected static NativeDispatcher nd;
// Our file descriptor
! protected FileDescriptor fd;
! protected final int fdVal;
// Lock held by thread currently blocked on this channel
! protected final ReentrantLock acceptLock = new ReentrantLock();
// Lock held by any thread that modifies the state fields declared below
// DO NOT invoke a blocking I/O operation while holding this lock!
! protected final Object stateLock = new Object();
// -- The following fields are protected by stateLock
// Channel state, increases monotonically
! protected static final int ST_INUSE = 0;
! protected static final int ST_CLOSING = 1;
! protected static final int ST_KILLPENDING = 2;
! protected static final int ST_KILLED = 3;
! protected int state;
// ID of native thread currently blocked in this channel, for signalling
! protected long thread;
// Binding
! protected InetSocketAddress localAddress; // null => unbound
// set true when exclusive binding is on and SO_REUSEADDR is emulated
! protected boolean isReuseAddress;
// Our socket adaptor, if any
! protected ServerSocket socket;
// -- End of fields protected by stateLock
! protected ServerSocketChannelImpl(SelectorProvider sp) throws IOException {
super(sp);
! this.fd = createFD();
this.fdVal = IOUtil.fdVal(fd);
}
! protected ServerSocketChannelImpl(SelectorProvider sp, FileDescriptor fd, boolean bound)
throws IOException
{
super(sp);
this.fd = fd;
this.fdVal = IOUtil.fdVal(fd);
if (bound) {
synchronized (stateLock) {
! localAddress = createLocalAddress(fd);
! }
}
}
+
+ protected FileDescriptor createFD() throws IOException {
+ return Net.serverSocket(true);
+ }
+
+ protected InetSocketAddress createLocalAddress(FileDescriptor fd)
+ throws IOException {
+ return Net.localAddress(fd);
}
// @throws ClosedChannelException if channel is closed
! protected void ensureOpen() throws ClosedChannelException {
if (!isOpen())
throw new ClosedChannelException();
}
@Override
*** 202,212 ****
return Collections.unmodifiableSet(set);
}
}
@Override
! public final Set<SocketOption<?>> supportedOptions() {
return DefaultOptionsHolder.defaultOptions;
}
@Override
public ServerSocketChannel bind(SocketAddress local, int backlog) throws IOException {
--- 211,221 ----
return Collections.unmodifiableSet(set);
}
}
@Override
! public Set<SocketOption<?>> supportedOptions() {
return DefaultOptionsHolder.defaultOptions;
}
@Override
public ServerSocketChannel bind(SocketAddress local, int backlog) throws IOException {
*** 232,242 ****
* Marks the beginning of an I/O operation that might block.
*
* @throws ClosedChannelException if the channel is closed
* @throws NotYetBoundException if the channel's socket has not been bound yet
*/
! private void begin(boolean blocking) throws ClosedChannelException {
if (blocking)
begin(); // set blocker to close channel if interrupted
synchronized (stateLock) {
ensureOpen();
if (localAddress == null)
--- 241,251 ----
* Marks the beginning of an I/O operation that might block.
*
* @throws ClosedChannelException if the channel is closed
* @throws NotYetBoundException if the channel's socket has not been bound yet
*/
! protected void begin(boolean blocking) throws ClosedChannelException {
if (blocking)
begin(); // set blocker to close channel if interrupted
synchronized (stateLock) {
ensureOpen();
if (localAddress == null)
*** 250,260 ****
* Marks the end of an I/O operation that may have blocked.
*
* @throws AsynchronousCloseException if the channel was closed due to this
* thread being interrupted on a blocking I/O operation.
*/
! private void end(boolean blocking, boolean completed)
throws AsynchronousCloseException
{
if (blocking) {
synchronized (stateLock) {
thread = 0;
--- 259,269 ----
* Marks the end of an I/O operation that may have blocked.
*
* @throws AsynchronousCloseException if the channel was closed due to this
* thread being interrupted on a blocking I/O operation.
*/
! protected void end(boolean blocking, boolean completed)
throws AsynchronousCloseException
{
if (blocking) {
synchronized (stateLock) {
thread = 0;
< prev index next >