// Loop until we receive a shutdown command while (endpoint.isRunning()) { //略。。。
try { //略。。。
Usocket=null; try { // Accept the next incoming connection from the server // socket //看这里看这里!!!!第一处 socket = endpoint.serverSocketAccept(); } catch (Exception ioe) { // We didn't get a socket endpoint.countDownConnection(); if (endpoint.isRunning()) { // Introduce delay if necessary errorDelay = handleExceptionWithDelay(errorDelay); // re-throw throw ioe; } else { break; } } // Successful accept, reset the error delay errorDelay = 0;
// Configure the socket if (endpoint.isRunning() && !endpoint.isPaused()) { // setSocketOptions() will hand the socket off to // an appropriate processor if successful //看这里看这里!!!!第二处 if (!endpoint.setSocketOptions(socket)) { endpoint.closeSocket(socket); } } else { endpoint.destroySocket(socket); } } catch (Throwable t) { //略。。。 } } state = AcceptorState.ENDED; }
/** * Process the specified connection. * * @param socket The socket channel * @return <code>true</code> if the socket was correctly configured * and processing may continue, <code>false</code> if the socket needs to be * close immediately */ @Override protectedbooleansetSocketOptions(SocketChannel socket) { // Process the connection try { //disable blocking, APR style, we are gonna be polling it socket.configureBlocking(false); Socketsock= socket.socket(); socketProperties.setProperties(sock);
/** * Return an available poller in true round robin fashion. * * @return The next poller in sequence */ public Poller getPoller0() { intidx= Math.abs(pollerRotater.incrementAndGet()) % pollers.length; return pollers[idx]; } /** * The socket pollers. */ private Poller[] pollers = null; privateAtomicIntegerpollerRotater=newAtomicInteger(0);