Author: markt
Date: Sun Oct  6 21:59:06 2013
New Revision: 1529702

URL: http://svn.apache.org/r1529702
Log:
No need to test dispatches.hasNext() more than once.
Add some additional comments.
Modified:
    tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java
    tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java

Modified: tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java?rev=1529702&r1=1529701&r2=1529702&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java (original)
+++ tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java Sun Oct  6 
21:59:06 2013
@@ -620,16 +620,12 @@ public abstract class AbstractProtocol<S
                 Iterator<DispatchType> dispatches = null;
                 do {
                     if (dispatches != null) {
-                        if (dispatches.hasNext()) {
-                            // Associate with the processor with the 
connection as
-                            // these calls may result in a nested call to 
process()
-                            connections.put(socket, processor);
-                            DispatchType nextDispatch = dispatches.next();
-                            state = processor.asyncDispatch(
-                                    nextDispatch.getSocketStatus());
-                        } else {
-                            dispatches = null;
-                        }
+                        // Associate with the processor with the connection as
+                        // these calls may result in a nested call to process()
+                        connections.put(socket, processor);
+                        DispatchType nextDispatch = dispatches.next();
+                        state = processor.asyncDispatch(
+                                nextDispatch.getSocketStatus());
                     } else if (status == SocketStatus.DISCONNECT &&
                             !processor.isComet()) {
                         // Do nothing here, just wait for it to get recycled
@@ -677,11 +673,13 @@ public abstract class AbstractProtocol<S
                                 "], State out: [" + state + "]");
                     }
                     if (dispatches == null || !dispatches.hasNext()) {
+                        // Only returns non-null iterator if there are
+                        // dispatches to process.
                         dispatches = wrapper.getIteratorAndClearDispatches();
                     }
                 } while (state == SocketState.ASYNC_END ||
                         state == SocketState.UPGRADING ||
-                        dispatches != null && dispatches.hasNext() && state != 
SocketState.CLOSED);
+                        dispatches != null && state != SocketState.CLOSED);
 
                 if (state == SocketState.LONG) {
                     // In the middle of processing a request/response. Keep the

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java?rev=1529702&r1=1529701&r2=1529702&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java Sun Oct  6 
21:59:06 2013
@@ -119,8 +119,13 @@ public class SocketWrapper<E> {
         }
     }
     public Iterator<DispatchType> getIteratorAndClearDispatches() {
+        // Note: Logic in AbstractProtocol depends on this method only 
returning
+        // a non-null value if the iterator is non-empty. i.e. it should never
+        // return an empty iterator.
         Iterator<DispatchType> result;
         synchronized (dispatches) {
+            // Synchronized as the generation of the iterator and the clearing
+            // of dispatches needs to be an atomic operation.
             result = dispatches.iterator();
             if (result.hasNext()) {
                 dispatches.clear();



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to