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 2008/11/20 17:04:55 UTC

svn commit: r719262 - in /tomcat/tc6.0.x/trunk/java/org/apache: catalina/connector/ coyote/ coyote/http11/ tomcat/util/net/

Author: fhanik
Date: Thu Nov 20 08:04:55 2008
New Revision: 719262

URL: http://svn.apache.org/viewvc?rev=719262&view=rev
Log:
port of http://svn.apache.org/viewvc?view=rev&revision=645175

Modified:
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CometEventImpl.java
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/Request.java
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/ActionCode.java
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11AprProcessor.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/connector/CometEventImpl.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CometEventImpl.java?rev=719262&r1=719261&r2=719262&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CometEventImpl.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CometEventImpl.java Thu Nov 20 08:04:55 2008
@@ -26,6 +26,7 @@
 
 import org.apache.catalina.CometEvent;
 import org.apache.catalina.util.StringManager;
+import org.apache.coyote.ActionCode;
 
 public class CometEventImpl implements CometEvent {
 
@@ -92,8 +93,10 @@
         if (request == null) {
             throw new IllegalStateException(sm.getString("cometEvent.nullRequest"));
         }
+        boolean iscomet = request.isComet();
         request.setComet(false);
         response.finishResponse();
+        if (iscomet) request.cometClose();
     }
 
     public EventSubType getEventSubType() {
@@ -116,6 +119,7 @@
             UnsupportedOperationException {
         if (request.getAttribute("org.apache.tomcat.comet.timeout.support") == Boolean.TRUE) {
             request.setAttribute("org.apache.tomcat.comet.timeout", new Integer(timeout));
+            if (request.isComet()) request.setCometTimeout((long)timeout);
         } else {
             throw new UnsupportedOperationException();
         }

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/Request.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/Request.java?rev=719262&r1=719261&r2=719262&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/Request.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/Request.java Thu Nov 20 08:04:55 2008
@@ -2262,6 +2262,13 @@
         return (inputBuffer.available() > 0);
     }
 
+    public void cometClose() {
+        coyoteRequest.action(ActionCode.ACTION_COMET_CLOSE,getEvent());
+    }
+    
+    public void setCometTimeout(long timeout) {
+        coyoteRequest.action(ActionCode.ACTION_COMET_SETTIMEOUT,new Long(timeout));
+    }
     
     // ------------------------------------------------------ Protected Methods
 

Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/ActionCode.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/ActionCode.java?rev=719262&r1=719261&r2=719262&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/ActionCode.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/ActionCode.java Thu Nov 20 08:04:55 2008
@@ -141,7 +141,7 @@
 
 
     /**
-     * Callback for begin Comet processing
+     * Callback for end Comet processing
      */
     public static final ActionCode ACTION_COMET_END = new ActionCode(22);
 
@@ -151,7 +151,16 @@
      */
     public static final ActionCode ACTION_AVAILABLE = new ActionCode(23);
 
+    /**
+     * Callback for an asynchronous close of the Comet event
+     */
+    public static final ActionCode ACTION_COMET_CLOSE = new ActionCode(24);
 
+    /**
+     * Callback for setting the timeout asynchronously
+     */
+    public static final ActionCode ACTION_COMET_SETTIMEOUT = new ActionCode(25);
+    
     // ----------------------------------------------------------- Constructors
     int code;
 

Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java?rev=719262&r1=719261&r2=719262&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java Thu Nov 20 08:04:55 2008
@@ -1211,6 +1211,10 @@
             comet = true;
         } else if (actionCode == ActionCode.ACTION_COMET_END) {
             comet = false;
+        } else if (actionCode == ActionCode.ACTION_COMET_CLOSE) {
+            //no op
+        } else if (actionCode == ActionCode.ACTION_COMET_SETTIMEOUT) {
+            //no op
         }
 
     }

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=719262&r1=719261&r2=719262&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 Nov 20 08:04:55 2008
@@ -778,7 +778,8 @@
             return SocketState.CLOSED;
         } else if (!comet) {
             recycle();
-            return SocketState.OPEN;
+            //pay attention to the keep alive flag set in process()
+            return (keepAlive)?SocketState.OPEN:SocketState.CLOSED;
         } else {
             return SocketState.LONG;
         }
@@ -1225,6 +1226,21 @@
             comet = true;
         } else if (actionCode == ActionCode.ACTION_COMET_END) {
             comet = false;
+        }  else if (actionCode == ActionCode.ACTION_COMET_CLOSE) {
+            NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment)socket.getAttachment(false);
+            attach.setCometOps(NioEndpoint.OP_CALLBACK);
+            //notify poller if not on a tomcat thread
+            RequestInfo rp = request.getRequestProcessor();
+            if ( rp.getStage() != org.apache.coyote.Constants.STAGE_SERVICE ) //async handling
+                socket.getPoller().cometInterest(socket);
+        } else if (actionCode == ActionCode.ACTION_COMET_SETTIMEOUT) {
+            if (param==null) return;
+            NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment)socket.getAttachment(false);
+            long timeout = ((Long)param).longValue();
+            //if we are not piggy backing on a worker thread, set the timeout
+            RequestInfo rp = request.getRequestProcessor();
+            if ( rp.getStage() != org.apache.coyote.Constants.STAGE_SERVICE ) //async handling
+                attach.setTimeout(timeout);
         }
 
     }

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=719262&r1=719261&r2=719262&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 Nov 20 08:04:55 2008
@@ -1635,6 +1635,7 @@
         protected void reg(SelectionKey sk, KeyAttachment attachment, int intops) {
             sk.interestOps(intops); 
             attachment.interestOps(intops);
+            attachment.setCometOps(intops);
         }
 
         protected void timeout(int keyCount, boolean hasEvents) {
@@ -1659,6 +1660,7 @@
                     } else if ( ka.getError() ) {
                         cancelledKey(key, SocketStatus.ERROR,true);
                     } else if (ka.getComet() && ka.getCometNotify() ) {
+                        ka.setCometNotify(false);
                         reg(key,ka,0);//avoid multiple calls, this gets reregistered after invokation
                         //if (!processSocket(ka.getChannel(), SocketStatus.OPEN_CALLBACK)) processSocket(ka.getChannel(), SocketStatus.DISCONNECT);
                         if (!processSocket(ka.getChannel(), SocketStatus.OPEN)) processSocket(ka.getChannel(), SocketStatus.DISCONNECT);



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