< prev index next >

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

Print this page
rev 49271 : [mq]: selector-cleanup


 193 
 194         private static Set<SocketOption<?>> defaultOptions() {
 195             HashSet<SocketOption<?>> set = new HashSet<>();
 196             set.add(StandardSocketOptions.SO_RCVBUF);
 197             set.add(StandardSocketOptions.SO_REUSEADDR);
 198             if (Net.isReusePortAvailable()) {
 199                 set.add(StandardSocketOptions.SO_REUSEPORT);
 200             }
 201             set.add(StandardSocketOptions.IP_TOS);
 202             return Collections.unmodifiableSet(set);
 203         }
 204     }
 205 
 206     @Override
 207     public final Set<SocketOption<?>> supportedOptions() {
 208         return DefaultOptionsHolder.defaultOptions;
 209     }
 210 
 211     @Override
 212     public ServerSocketChannel bind(SocketAddress local, int backlog) throws IOException {
 213         acceptLock.lock();
 214         try {
 215             synchronized (stateLock) {
 216                 ensureOpen();
 217                 if (localAddress != null)
 218                     throw new AlreadyBoundException();
 219                 InetSocketAddress isa = (local == null)
 220                                         ? new InetSocketAddress(0)
 221                                         : Net.checkAddress(local);
 222                 SecurityManager sm = System.getSecurityManager();
 223                 if (sm != null)
 224                     sm.checkListen(isa.getPort());
 225                 NetHooks.beforeTcpBind(fd, isa.getAddress(), isa.getPort());
 226                 Net.bind(fd, isa.getAddress(), isa.getPort());
 227                 Net.listen(fd, backlog < 1 ? 50 : backlog);
 228                 localAddress = Net.localAddress(fd);
 229             }
 230         } finally {
 231             acceptLock.unlock();
 232         }
 233         return this;
 234     }
 235 
 236     /**
 237      * Marks the beginning of an I/O operation that might block.
 238      *
 239      * @throws ClosedChannelException if the channel is closed
 240      * @throws NotYetBoundException if the channel's socket has not been bound yet
 241      */
 242     private void begin(boolean blocking) throws ClosedChannelException {
 243         if (blocking)
 244             begin();  // set blocker to close channel if interrupted
 245         synchronized (stateLock) {
 246             ensureOpen();
 247             if (localAddress == null)
 248                 throw new NotYetBoundException();
 249             if (blocking)
 250                 thread = NativeThread.current();
 251         }
 252     }




 193 
 194         private static Set<SocketOption<?>> defaultOptions() {
 195             HashSet<SocketOption<?>> set = new HashSet<>();
 196             set.add(StandardSocketOptions.SO_RCVBUF);
 197             set.add(StandardSocketOptions.SO_REUSEADDR);
 198             if (Net.isReusePortAvailable()) {
 199                 set.add(StandardSocketOptions.SO_REUSEPORT);
 200             }
 201             set.add(StandardSocketOptions.IP_TOS);
 202             return Collections.unmodifiableSet(set);
 203         }
 204     }
 205 
 206     @Override
 207     public final Set<SocketOption<?>> supportedOptions() {
 208         return DefaultOptionsHolder.defaultOptions;
 209     }
 210 
 211     @Override
 212     public ServerSocketChannel bind(SocketAddress local, int backlog) throws IOException {


 213         synchronized (stateLock) {
 214             ensureOpen();
 215             if (localAddress != null)
 216                 throw new AlreadyBoundException();
 217             InetSocketAddress isa = (local == null)
 218                                     ? new InetSocketAddress(0)
 219                                     : Net.checkAddress(local);
 220             SecurityManager sm = System.getSecurityManager();
 221             if (sm != null)
 222                 sm.checkListen(isa.getPort());
 223             NetHooks.beforeTcpBind(fd, isa.getAddress(), isa.getPort());
 224             Net.bind(fd, isa.getAddress(), isa.getPort());
 225             Net.listen(fd, backlog < 1 ? 50 : backlog);
 226             localAddress = Net.localAddress(fd);
 227         }



 228         return this;
 229     }
 230 
 231     /**
 232      * Marks the beginning of an I/O operation that might block.
 233      *
 234      * @throws ClosedChannelException if the channel is closed
 235      * @throws NotYetBoundException if the channel's socket has not been bound yet
 236      */
 237     private void begin(boolean blocking) throws ClosedChannelException {
 238         if (blocking)
 239             begin();  // set blocker to close channel if interrupted
 240         synchronized (stateLock) {
 241             ensureOpen();
 242             if (localAddress == null)
 243                 throw new NotYetBoundException();
 244             if (blocking)
 245                 thread = NativeThread.current();
 246         }
 247     }


< prev index next >