src/java.base/share/classes/sun/nio/ch/ServerSocketChannelImpl.java
changeset 58900 434329f6f456
parent 55081 dd321e3596c0
child 58911 2c777f25cfff
equal deleted inserted replaced
58899:5573a7098439 58900:434329f6f456
   330                         }
   330                         }
   331                         park(Net.POLLIN, remainingNanos);
   331                         park(Net.POLLIN, remainingNanos);
   332                         n = Net.accept(fd, newfd, isaa);
   332                         n = Net.accept(fd, newfd, isaa);
   333                     }
   333                     }
   334                 } finally {
   334                 } finally {
   335                     // restore socket to blocking mode
   335                     // restore socket to blocking mode (if channel is open)
   336                     lockedConfigureBlocking(true);
   336                     tryLockedConfigureBlocking(true);
   337                 }
   337                 }
   338             } finally {
   338             } finally {
   339                 end(true, n > 0);
   339                 end(true, n > 0);
   340             }
   340             }
   341         } finally {
   341         } finally {
   374             acceptLock.unlock();
   374             acceptLock.unlock();
   375         }
   375         }
   376     }
   376     }
   377 
   377 
   378     /**
   378     /**
   379      * Adjust the blocking mode while holding acceptLock.
   379      * Adjust the blocking. acceptLock must already be held.
   380      */
   380      */
   381     private void lockedConfigureBlocking(boolean block) throws IOException {
   381     private void lockedConfigureBlocking(boolean block) throws IOException {
   382         assert acceptLock.isHeldByCurrentThread();
   382         assert acceptLock.isHeldByCurrentThread();
   383         synchronized (stateLock) {
   383         synchronized (stateLock) {
   384             ensureOpen();
   384             ensureOpen();
   385             IOUtil.configureBlocking(fd, block);
   385             IOUtil.configureBlocking(fd, block);
       
   386         }
       
   387     }
       
   388 
       
   389     /**
       
   390      * Adjusts the blocking mode if the channel is open. acceptLock must already
       
   391      * be held.
       
   392      *
       
   393      * @return {@code true} if the blocking mode was adjusted, {@code false} if
       
   394      *         the blocking mode was not adjusted because the channel is closed
       
   395      */
       
   396     private boolean tryLockedConfigureBlocking(boolean block) throws IOException {
       
   397         assert acceptLock.isHeldByCurrentThread();
       
   398         synchronized (stateLock) {
       
   399             if (isOpen()) {
       
   400                 IOUtil.configureBlocking(fd, block);
       
   401                 return true;
       
   402             } else {
       
   403                 return false;
       
   404             }
   386         }
   405         }
   387     }
   406     }
   388 
   407 
   389     /**
   408     /**
   390      * Closes the socket if there are no accept in progress and the channel is
   409      * Closes the socket if there are no accept in progress and the channel is