implement a bit cleanup and a rough estimate on the size of a poller
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 8 Dec 2008 15:52:23 +0000 (15:52 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 8 Dec 2008 15:52:23 +0000 (15:52 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@724384 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/tomcat/util/net/NioEndpoint.java

index dd3eea8..aebdce1 100644 (file)
@@ -1280,12 +1280,14 @@ public class NioEndpoint {
         
         protected CountDownLatch stopLatch = new CountDownLatch(1);
 
-
+        protected volatile int keyCount = 0;
 
         public Poller() throws IOException {
             this.selector = Selector.open();
         }
         
+        public int getKeyCount() { return keyCount; }
+        
         public Selector getSelector() { return selector;}
 
         /**
@@ -1380,8 +1382,9 @@ public class NioEndpoint {
                     //processSocket(ka.getChannel(), status, dispatch);
                     ka.setComet(false);//to avoid a loop
                     if (status == SocketStatus.TIMEOUT ) {
-                        processSocket(ka.getChannel(), status, true);
-                        return; // don't close on comet timeout
+                        if (processSocket(ka.getChannel(), status, true)) {
+                            return; // don't close on comet timeout
+                        }
                     } else {
                         processSocket(ka.getChannel(), status, false); //don't dispatch if the lines below are cancelling the key
                     }                    
@@ -1430,7 +1433,8 @@ public class NioEndpoint {
                                 //do a non blocking select
                                 keyCount = selector.selectNow();
                             }else {
-                                wakeupCounter.set( -1);
+                                keyCount = selector.keys().size();
+                                wakeupCounter.set(-1);
                                 keyCount = selector.select(selectorTimeout);
                             }
                             wakeupCounter.set(0);