Author: fhanik
Date: Thu Jul 13 12:51:56 2006
New Revision: 421694

URL: http://svn.apache.org/viewvc?rev=421694&view=rev
Log:
Set a per connection timeout

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

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/CometProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/CometProcessor.java?rev=421694&r1=421693&r2=421694&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/CometProcessor.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/CometProcessor.java Thu Jul 
13 12:51:56 2006
@@ -117,7 +117,7 @@
      * This method should not be called asynchronously, as that will have no 
effect.
      * @param request The HTTP servlet request instance
      * @param response The HTTP servlet response instance
-     * @param timeout The timeout in milliseconds for this connection
+     * @param timeout The timeout in milliseconds for this connection, must be 
a positive value, larger than 0
      * @throws IOException An IOException may be thrown to indicate an IO 
error, 
      *         or that the EOF has been reached on the connection
      * @throws ServletException An exception has occurred, as specified by the 
root

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java?rev=421694&r1=421693&r2=421694&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java 
Thu Jul 13 12:51:56 2006
@@ -743,7 +743,11 @@
             SelectionKey key = 
socket.keyFor(endpoint.getPoller().getSelector());
             if ( key != null ) {
                 NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment) 
key.attachment();
-                if ( attach!=null ) attach.setComet(comet);
+                if ( attach!=null ) {
+                    attach.setComet(comet);
+                    Integer comettimeout = 
(Integer)request.getAttribute("org.apache.tomcat.comet.timeout");
+                    if ( comettimeout != null ) 
attach.setTimeout(comettimeout.longValue());
+                }
             }
             
         } catch (InterruptedIOException e) {
@@ -884,7 +888,11 @@
                     SelectionKey key = 
socket.keyFor(endpoint.getPoller().getSelector());
                     if (key != null) {
                         NioEndpoint.KeyAttachment attach = 
(NioEndpoint.KeyAttachment) key.attachment();
-                        if (attach != null) attach.setComet(comet);
+                        if (attach != null)  {
+                            attach.setComet(comet);
+                            Integer comettimeout = (Integer) 
request.getAttribute("org.apache.tomcat.comet.timeout");
+                            if (comettimeout != null) 
attach.setTimeout(comettimeout.longValue());
+                        }
                     }
                 } catch (InterruptedIOException e) {
                     error = true;
@@ -1397,6 +1405,8 @@
 
         // Advertise comet support through a request attribute
         request.setAttribute("org.apache.tomcat.comet.support", Boolean.TRUE);
+        // Advertise comet timeout support
+        request.setAttribute("org.apache.tomcat.comet.timeout.support", 
Boolean.TRUE);
 
     }
 

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=421694&r1=421693&r2=421694&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 
Jul 13 12:51:56 2006
@@ -1158,16 +1158,17 @@
                 }//while
 
                 //timeout
-                Set keys = selector.keys();
+                Set<SelectionKey> keys = selector.keys();
                 long now = System.currentTimeMillis();
-                for (Iterator iter = keys.iterator(); iter.hasNext(); ) {
-                    SelectionKey key = (SelectionKey) iter.next();
+                for (Iterator<SelectionKey> iter = keys.iterator(); 
iter.hasNext(); ) {
+                    SelectionKey key = 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) {
+                            boolean isTimedout = (ka.getTimeout()==-1)?(delta 
> (long) soTimeout):(delta>ka.getTimeout());
+                            if (isTimedout) {
                                 cancelledKey(key);
                             }
                         }
@@ -1197,11 +1198,14 @@
         public boolean getWakeUp() { return wakeUp; }
         public void setWakeUp(boolean wakeUp) { this.wakeUp = wakeUp; }
         public Object getMutex() {return mutex;}
+        public void setTimeout(long timeout) {this.timeout = timeout;}
+        public long getTimeout() {return this.timeout;}
         protected Object mutex = new Object();
         protected boolean wakeUp = false;
         protected long lastAccess = System.currentTimeMillis();
         protected boolean currentAccess = false;
         protected boolean comet = false;
+        protected long timeout = -1;
 
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to