Two fixes,
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 22 Jun 2006 20:28:27 +0000 (20:28 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 22 Jun 2006 20:28:27 +0000 (20:28 +0000)
process timeouts last, no need to check a timeout on a valid read. hence we do it after we process the actual operations
Throw an IO exception if we reach end of stream so that the sockets can get properly closed down
Speed is the same for nio and io right now, nio seems just a tad faster without keep alives

git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@416461 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/coyote/http11/InternalNioInputBuffer.java
java/org/apache/tomcat/util/net/NioEndpoint.java

index 3959f1a..2a95757 100644 (file)
@@ -559,7 +559,8 @@ public class InternalNioInputBuffer implements InputBuffer {
                 lastValid = pos + nRead;\r
                 return true;\r
             } else if (nRead == -1) {\r
-                return false;\r
+                //return false;\r
+                throw new IOException("end of stream reached.");\r
             }\r
             timedOut = (readTimeout != -1) && ((System.currentTimeMillis()-start)>this.readTimeout);\r
             if ( !timedOut && nRead == 0 ) \r
index 9665922..a3d1a48 100644 (file)
@@ -1191,32 +1191,15 @@ public class NioEndpoint {
                     log.error("",x);\r
                     continue;\r
                 }\r
-                //timeout\r
-                Set keys = selector.keys();\r
-                long now = System.currentTimeMillis();\r
-                for (Iterator iter = keys.iterator(); iter.hasNext(); ) {\r
-                    SelectionKey key = (SelectionKey) iter.next();\r
-                    try {\r
-                        if (key.interestOps() == SelectionKey.OP_READ) {\r
-                            //only timeout sockets that we are waiting for a read from\r
-                            KeyAttachment ka = (KeyAttachment) key.attachment();\r
-                            long delta = now - ka.getLastAccess();\r
-                            if (delta > (long) soTimeout) {\r
-                                cancelledKey(key);\r
-                            }\r
-                        }\r
-                    }catch ( CancelledKeyException ckx ) {\r
-                        cancelledKey(key);\r
-                    }\r
-                }\r
+                \r
             \r
 \r
-                if (keyCount == 0) continue;\r
+                //if (keyCount == 0) continue;\r
 \r
-                Iterator iterator = selector.selectedKeys().iterator();\r
+                Iterator iterator = keyCount > 0 ? selector.selectedKeys().iterator() : null;\r
                 // Walk through the collection of ready keys and dispatch\r
                 // any active event.\r
-                while (iterator.hasNext()) {\r
+                while (iterator != null && iterator.hasNext()) {\r
                     SelectionKey sk = (SelectionKey) iterator.next();\r
                     iterator.remove();\r
                     KeyAttachment attachment = (KeyAttachment)sk.attachment();\r
@@ -1255,7 +1238,25 @@ public class NioEndpoint {
                     }\r
                 }//while\r
 \r
-                \r
+                //timeout\r
+                Set keys = selector.keys();\r
+                long now = System.currentTimeMillis();\r
+                for (Iterator iter = keys.iterator(); iter.hasNext(); ) {\r
+                    SelectionKey key = (SelectionKey) iter.next();\r
+                    try {\r
+                        if (key.interestOps() == SelectionKey.OP_READ) {\r
+                            //only timeout sockets that we are waiting for a read from\r
+                            KeyAttachment ka = (KeyAttachment) key.attachment();\r
+                            long delta = now - ka.getLastAccess();\r
+                            if (delta > (long) soTimeout) {\r
+                                cancelledKey(key);\r
+                            }\r
+                        }\r
+                    }catch ( CancelledKeyException ckx ) {\r
+                        cancelledKey(key);\r
+                    }\r
+                }\r
+\r
             }\r
             synchronized (this) {\r
                 this.notifyAll();\r