Dont do the not needed operations, if they are not needed.
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 22 Jun 2006 22:02:23 +0000 (22:02 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 22 Jun 2006 22:02:23 +0000 (22:02 +0000)
Performance is just a tad under java.io, which is expected as we need to poll, as opposed to constantly wait for data.

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

java/org/apache/coyote/http11/InternalNioInputBuffer.java

index 2a95757..44d102f 100644 (file)
@@ -567,10 +567,14 @@ public class InternalNioInputBuffer implements InputBuffer {
                 try {\r
                     final SelectionKey key = socket.keyFor(poller.getSelector());\r
                     final KeyAttachment att = (KeyAttachment)key.attachment();\r
-                    att.setWakeUp(true);\r
-                    \r
-                    poller.addEvent(\r
-                        new Runnable() {\r
+                    //to do, add in a check, we might have just timed out on the wait,\r
+                    //so there is no need to register us again.\r
+                    boolean addToQueue = false;\r
+                    try { addToQueue = ((key.interestOps()&SelectionKey.OP_READ) != SelectionKey.OP_READ); } catch ( CancelledKeyException ignore ){}\r
+                    if ( addToQueue ) {\r
+                        att.setWakeUp(true);\r
+                        poller.addEvent(\r
+                            new Runnable() {\r
                             public void run() {\r
                                 try {\r
                                     if (key != null) key.interestOps(SelectionKey.OP_READ);\r
@@ -582,12 +586,16 @@ public class InternalNioInputBuffer implements InputBuffer {
                                     } catch (Exception ignore) {}\r
                                 }\r
                             }\r
-                    });\r
-                    synchronized (att.getMutex()) { att.getMutex().wait(25);}\r
+                        });\r
+                    }//end if\r
+                    synchronized (att.getMutex()) {\r
+                        if ( att.getWakeUp() ) att.getMutex().wait(25);\r
+                    }\r
                 }catch ( Exception x ) {}\r
         }while ( nRead == 0 && (!timedOut) );\r
         //else throw new IOException(sm.getString("iib.failedread"));\r
-        return false; //timeout\r
+        //return false; //timeout\r
+        throw new IOException("read timed out.");\r
     }\r
 \r
 \r