< prev index next >

src/java.base/share/classes/sun/nio/ch/ServerSocketChannelImpl.java

Print this page

        

@@ -52,73 +52,82 @@
 
 /**
  * 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);
         this.fd =  fd;
         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();
     }
 
     @Override

@@ -202,11 +211,11 @@
             return Collections.unmodifiableSet(set);
         }
     }
 
     @Override
-    public final Set<SocketOption<?>> supportedOptions() {
+    public Set<SocketOption<?>> supportedOptions() {
         return DefaultOptionsHolder.defaultOptions;
     }
 
     @Override
     public ServerSocketChannel bind(SocketAddress local, int backlog) throws IOException {

@@ -232,11 +241,11 @@
      * 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 {
+    protected void begin(boolean blocking) throws ClosedChannelException {
         if (blocking)
             begin();  // set blocker to close channel if interrupted
         synchronized (stateLock) {
             ensureOpen();
             if (localAddress == null)

@@ -250,11 +259,11 @@
      * 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)
+    protected void end(boolean blocking, boolean completed)
         throws AsynchronousCloseException
     {
         if (blocking) {
             synchronized (stateLock) {
                 thread = 0;
< prev index next >