Fix various odd behaviours seen with a debugger. Observed both multiple and zero...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 25 Jan 2011 17:20:20 +0000 (17:20 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 25 Jan 2011 17:20:20 +0000 (17:20 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1063366 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/coyote/http11/Http11NioProtocol.java
java/org/apache/coyote/http11/LocalStrings.properties
webapps/docs/changelog.xml

index 375a93f..0735d80 100644 (file)
@@ -17,6 +17,8 @@
 
 package org.apache.coyote.http11;
 
+import java.io.IOException;
+import java.nio.channels.SelectionKey;
 import java.nio.channels.SocketChannel;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
@@ -317,8 +319,10 @@ public class Http11NioProtocol extends AbstractHttp11JsseProtocol {
                         } else {
                             // Comet
                             if (log.isDebugEnabled()) log.debug("Keeping processor["+processor);
-                            //add correct poller events here based on Comet stuff
-                            socket.getPoller().add(socket,att.getCometOps());
+                            // May receive more data from client
+                            SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector());
+                            key.interestOps(SelectionKey.OP_READ);
+                            att.interestOps(SelectionKey.OP_READ);
                         }
                     } else {
                         // state == SocketState.ASYNC_END
@@ -358,8 +362,11 @@ public class Http11NioProtocol extends AbstractHttp11JsseProtocol {
                     connections.put(socket, processor);
                     
                     if (processor.comet) {
+                        // May receive more data from client
+                        SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector());
                         NioEndpoint.KeyAttachment att = (NioEndpoint.KeyAttachment)socket.getAttachment(false);
-                        socket.getPoller().add(socket,att.getCometOps());
+                        key.interestOps(SelectionKey.OP_READ);
+                        att.interestOps(SelectionKey.OP_READ);
                     } else if (processor.isAsync()) {
                         NioEndpoint.KeyAttachment att = (NioEndpoint.KeyAttachment)socket.getAttachment(false);
                         att.setAsync(true);
@@ -367,7 +374,10 @@ public class Http11NioProtocol extends AbstractHttp11JsseProtocol {
                         // complete or dispatch)
                         state = processor.asyncPostProcess();
                     } else {
-                        socket.getPoller().add(socket);
+                        // Error condition. A connection in this state should
+                        // by using one of async or comet
+                        throw new IOException(sm.getString(
+                                "http11protocol.state.long.error"));
                     }
                 }
                 if (state == SocketState.LONG || state == SocketState.ASYNC_END) {
index c0c27fc..92e1933 100644 (file)
@@ -20,6 +20,7 @@ http11protocol.proto.ioexception.info=IOException reading request, ignored
 http11protocol.proto.socketexception.debug=SocketException reading request
 http11protocol.proto.socketexception.info=SocketException reading request, ignored
 http11protocol.start=Starting Coyote HTTP/1.1 on {0}
+http11protocol.state.long.error=Error processing request. Socket is in the long poll state but neither Servlet 3.0+ async or Comet is being used 
 
 http11processor.regexp.error=Error parsing regular expression {0}
 http11processor.filter.unknown=Unknown filter {0}
index 0b9b7c9..21dfe27 100644 (file)
         Ensure correct recycling of NIO input filters when processing Comet
         events. (markt)
       </fix>
+      <fix>
+        Correct interaction of NIO socket and Poller when processing Comet
+        events. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">