src/java.base/share/classes/sun/nio/ch/ServerSocketChannelImpl.java
branchunixdomainchannels
changeset 58911 2c777f25cfff
parent 58847 692de65ab293
parent 58900 434329f6f456
equal deleted inserted replaced
58857:12b08b510fd0 58911:2c777f25cfff
   227                         }
   227                         }
   228                         park(Net.POLLIN, remainingNanos);
   228                         park(Net.POLLIN, remainingNanos);
   229                         n = implAccept(fd, newfd, isaa);
   229                         n = implAccept(fd, newfd, isaa);
   230                     }
   230                     }
   231                 } finally {
   231                 } finally {
   232                     // restore socket to blocking mode
   232                     // restore socket to blocking mode (if channel is open)
   233                     lockedConfigureBlocking(true);
   233                     tryLockedConfigureBlocking(true);
   234                 }
   234                 }
   235             } finally {
   235             } finally {
   236                 end(true, n > 0);
   236                 end(true, n > 0);
   237             }
   237             }
   238         } finally {
   238         } finally {
   255             acceptLock.unlock();
   255             acceptLock.unlock();
   256         }
   256         }
   257     }
   257     }
   258 
   258 
   259     /**
   259     /**
   260      * Adjust the blocking mode while holding acceptLock.
   260      * Adjust the blocking. acceptLock must already be held.
   261      */
   261      */
   262     private void lockedConfigureBlocking(boolean block) throws IOException {
   262     private void lockedConfigureBlocking(boolean block) throws IOException {
   263         assert acceptLock.isHeldByCurrentThread();
   263         assert acceptLock.isHeldByCurrentThread();
   264         synchronized (stateLock) {
   264         synchronized (stateLock) {
   265             ensureOpen();
   265             ensureOpen();
   266             IOUtil.configureBlocking(fd, block);
   266             IOUtil.configureBlocking(fd, block);
       
   267         }
       
   268     }
       
   269 
       
   270     /**
       
   271      * Adjusts the blocking mode if the channel is open. acceptLock must already
       
   272      * be held.
       
   273      *
       
   274      * @return {@code true} if the blocking mode was adjusted, {@code false} if
       
   275      *         the blocking mode was not adjusted because the channel is closed
       
   276      */
       
   277     private boolean tryLockedConfigureBlocking(boolean block) throws IOException {
       
   278         assert acceptLock.isHeldByCurrentThread();
       
   279         synchronized (stateLock) {
       
   280             if (isOpen()) {
       
   281                 IOUtil.configureBlocking(fd, block);
       
   282                 return true;
       
   283             } else {
       
   284                 return false;
       
   285             }
   267         }
   286         }
   268     }
   287     }
   269 
   288 
   270     /**
   289     /**
   271      * Closes the socket if there are no accept in progress and the channel is
   290      * Closes the socket if there are no accept in progress and the channel is