--- old/src/java.base/share/classes/sun/nio/ch/ServerSocketChannelImpl.java 2018-05-03 16:52:25.517492701 -0700 +++ new/src/java.base/share/classes/sun/nio/ch/ServerSocketChannelImpl.java 2018-05-03 16:52:25.291492716 -0700 @@ -54,55 +54,55 @@ * An implementation of ServerSocketChannels */ -class ServerSocketChannelImpl +public class ServerSocketChannelImpl extends ServerSocketChannel implements SelChImpl { // Used to make native close and configure calls - private static NativeDispatcher nd; + protected static NativeDispatcher nd; // Our file descriptor - private final FileDescriptor fd; - private final int fdVal; + protected FileDescriptor fd; + protected final int fdVal; // Lock held by thread currently blocked on this channel - private final ReentrantLock acceptLock = new ReentrantLock(); + 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! - private final Object stateLock = new Object(); + protected 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; + 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 - private long thread; + protected long thread; // Binding - private InetSocketAddress localAddress; // null => unbound + protected InetSocketAddress localAddress; // null => unbound // set true when exclusive binding is on and SO_REUSEADDR is emulated - private boolean isReuseAddress; + protected boolean isReuseAddress; // Our socket adaptor, if any - private ServerSocket socket; + protected ServerSocket socket; // -- End of fields protected by stateLock - ServerSocketChannelImpl(SelectorProvider sp) throws IOException { + protected ServerSocketChannelImpl(SelectorProvider sp) throws IOException { super(sp); - this.fd = Net.serverSocket(true); + this.fd = createFD(); this.fdVal = IOUtil.fdVal(fd); } - ServerSocketChannelImpl(SelectorProvider sp, FileDescriptor fd, boolean bound) + protected ServerSocketChannelImpl(SelectorProvider sp, FileDescriptor fd, boolean bound) throws IOException { super(sp); @@ -110,13 +110,22 @@ this.fdVal = IOUtil.fdVal(fd); if (bound) { synchronized (stateLock) { - localAddress = Net.localAddress(fd); + 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 - private void ensureOpen() throws ClosedChannelException { + protected void ensureOpen() throws ClosedChannelException { if (!isOpen()) throw new ClosedChannelException(); } @@ -204,7 +213,7 @@ } @Override - public final Set> supportedOptions() { + public Set> supportedOptions() { return DefaultOptionsHolder.defaultOptions; } @@ -234,7 +243,7 @@ * @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 { + protected void begin(boolean blocking) throws ClosedChannelException { if (blocking) begin(); // set blocker to close channel if interrupted synchronized (stateLock) { @@ -252,7 +261,7 @@ * @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) + protected void end(boolean blocking, boolean completed) throws AsynchronousCloseException { if (blocking) {