Author: fhanik Date: Fri Jun 16 13:55:06 2006 New Revision: 414906 URL: http://svn.apache.org/viewvc?rev=414906&view=rev Log: Fixed comet processing. The following bug was existing: When a comet request had begun, and the browser sent some more data, the Tomcat APR component was never reading the data from the socket and lead to two kinds of failures 1. The CometServlet.read returned false, cause no data was read, and the socket closed 2. If the CometServlet.read was overwritten and return true, the thread got stuck in a loop, forever hanging.
The solution was to read the incoming data from the socket, update the content length of the request, and make sure that the input filters would still allow to read the data. I think the following features still need to be fixed: 1. If CometServlet.read return false, the adapter should call CometServlet.end, not CometServlet.error 2. If CometServlet.read throws an error, then the adapter should call CometServlet.error 3. When CometServlet.read returns false, don't close the socket, keep alive should still work and we should still be able to process more HTTP requests on that connection Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java 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=414906&r1=414905&r2=414906&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 Fri Jun 16 13:55:06 2006 @@ -743,9 +743,19 @@ try { rp.setStage(org.apache.coyote.Constants.STAGE_SERVICE); - error = !adapter.event(request, response, error); - if (request.getAttribute("org.apache.tomcat.comet") == null) { - comet = false; + int data = inputBuffer.readSocketData(); + if ( data > 0 ) { + int contentLength = request.getContentLength(); + if (contentLength>=0) request.setContentLength(contentLength + data); + for (int i=0; i<inputBuffer.activeFilters.length; i++) { + //this resets the remaining flag and the content length on the filter + //if we don't do this, then request.getInputStream.read will return 0 + if (inputBuffer.activeFilters[i]!=null) inputBuffer.activeFilters[i].setRequest(request); + } + error = !adapter.event(request, response, error); + if (request.getAttribute("org.apache.tomcat.comet") == null) { + comet = false; + } } } catch (InterruptedIOException e) { error = true; Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java?rev=414906&r1=414905&r2=414906&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java Fri Jun 16 13:55:06 2006 @@ -350,6 +350,17 @@ } } + + public int readSocketData() { + bbuf.clear(); + int nRead = Socket.recvbbt(socket, 0, buf.length - lastValid, readTimeout); + if (nRead > 0) { + bbuf.limit(nRead); + bbuf.get(buf, pos, nRead); + lastValid = pos + nRead; + } + return nRead>=0?nRead:-1; + } /** --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]