You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by fh...@apache.org on 2006/06/22 22:28:27 UTC

svn commit: r416461 - in /tomcat/tc6.0.x/trunk/java/org/apache: coyote/http11/InternalNioInputBuffer.java tomcat/util/net/NioEndpoint.java

Author: fhanik
Date: Thu Jun 22 13:28:27 2006
New Revision: 416461

URL: http://svn.apache.org/viewvc?rev=416461&view=rev
Log:
Two fixes,
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

Modified:
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java
    tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java

Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java?rev=416461&r1=416460&r2=416461&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java Thu Jun 22 13:28:27 2006
@@ -559,7 +559,8 @@
                 lastValid = pos + nRead;
                 return true;
             } else if (nRead == -1) {
-                return false;
+                //return false;
+                throw new IOException("end of stream reached.");
             }
             timedOut = (readTimeout != -1) && ((System.currentTimeMillis()-start)>this.readTimeout);
             if ( !timedOut && nRead == 0 ) 

Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=416461&r1=416460&r2=416461&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Thu Jun 22 13:28:27 2006
@@ -1191,32 +1191,15 @@
                     log.error("",x);
                     continue;
                 }
-                //timeout
-                Set keys = selector.keys();
-                long now = System.currentTimeMillis();
-                for (Iterator iter = keys.iterator(); iter.hasNext(); ) {
-                    SelectionKey key = (SelectionKey) iter.next();
-                    try {
-                        if (key.interestOps() == SelectionKey.OP_READ) {
-                            //only timeout sockets that we are waiting for a read from
-                            KeyAttachment ka = (KeyAttachment) key.attachment();
-                            long delta = now - ka.getLastAccess();
-                            if (delta > (long) soTimeout) {
-                                cancelledKey(key);
-                            }
-                        }
-                    }catch ( CancelledKeyException ckx ) {
-                        cancelledKey(key);
-                    }
-                }
+                
             
 
-                if (keyCount == 0) continue;
+                //if (keyCount == 0) continue;
 
-                Iterator iterator = selector.selectedKeys().iterator();
+                Iterator iterator = keyCount > 0 ? selector.selectedKeys().iterator() : null;
                 // Walk through the collection of ready keys and dispatch
                 // any active event.
-                while (iterator.hasNext()) {
+                while (iterator != null && iterator.hasNext()) {
                     SelectionKey sk = (SelectionKey) iterator.next();
                     iterator.remove();
                     KeyAttachment attachment = (KeyAttachment)sk.attachment();
@@ -1255,7 +1238,25 @@
                     }
                 }//while
 
-                
+                //timeout
+                Set keys = selector.keys();
+                long now = System.currentTimeMillis();
+                for (Iterator iter = keys.iterator(); iter.hasNext(); ) {
+                    SelectionKey key = (SelectionKey) iter.next();
+                    try {
+                        if (key.interestOps() == SelectionKey.OP_READ) {
+                            //only timeout sockets that we are waiting for a read from
+                            KeyAttachment ka = (KeyAttachment) key.attachment();
+                            long delta = now - ka.getLastAccess();
+                            if (delta > (long) soTimeout) {
+                                cancelledKey(key);
+                            }
+                        }
+                    }catch ( CancelledKeyException ckx ) {
+                        cancelledKey(key);
+                    }
+                }
+
             }
             synchronized (this) {
                 this.notifyAll();



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