On 10/06/2010 9:49 PM, Konstantin Kolinko wrote: > 2010/6/8 Reich, Matthias: > > I modified the code (in 6.0.20 and 6.0.26) so that the > error flag is not set. > > With that change Tomcat kept the connection open: > > > > ... > > if (response.isClosed() || !request.isComet()) { > > if (status==SocketStatus.OPEN) { > > //CometEvent.close was called during an event. > > request.getEvent().setEventType(CometEvent.EventType.END); > > request.getEvent().setEventSubType(null); > > > > // don't set the error flag here - otherwise the connection > will be closed > > // whenever a long poll is answered already during event handling: > > // error = true; > > > > 1. I think that I do not understand you. What is your meaning of "long > poll"? Can you describe your situation as a sequence of events how > they occur step-by-step on a timeline?
The concept of long poll is e.g. described in http://www.javaworld.com/javaworld/jw-03-2008/jw-03-asynchhttp.html?page=6 The sequence of events in my situation is as follows: - a poll request is received by the server - the CoyoteAdapter.service method is called and in turn invokes the servlet's event method with a BEGIN event - request.isComet() is still true when the control returns to the CoyoteAdapter.service method - some other thread writes a response and closes the Writer of the response - the CoyoteAdapter.event method is called and in turn invokes the servlet's event method with an END event - the servlet calls event.close() - when the control returns to the CoyoteAdapter.event method we have exactly this situation: response.isClosed() && !request.isComet() && status==SocketStatus.OPEN - thus, if the error flag is set in this situation, the connection will be closed, and a new connection must be opened by the browser for the subsequent poll request According to the above sequence I would expect that the connection is always closed if request.isComet() is still true when control returns to the CoyoteAdapter.service method after processing the BEGIN event - no matter how long it takes from then until the response is written. Surprisingly, I did not always observe this. Anyway, if the error flag is not set in this situation, the connection is kept open. > > 2. The above fragment when using Comet should be equivalent to > > > if (response.isClosed()) { > > if (status==SocketStatus.OPEN) { > > //CometEvent.close was called during an event. > > request.getEvent().setEventType(CometEvent.EventType.END); > > request.getEvent().setEventSubType(null); > > > > // don't set the error flag here - otherwise the connection > will be closed > > // whenever a long poll is answered already during event handling: > > // error = true; > > > > Response#isClosed(): > public boolean isClosed() { > return outputBuffer.isClosed(); > } No, it is not equivalent: response.isClosed() is true after closing the Writer or OutputStream, whereas request.isComet() is true until event.close() is called. > > If you will not be able to send your answer, why not to close the > socket right away? I was able to send the answer and would like to use the connection also for the next poll request. (or for some other request the browser decides to send through this connection) > > 3. It would be much more readable, if you provided your changes in the > unified diff format. (even better if it were generated with "svn diff" > command against sources retrieved from svn). > --- C:\DOCUME~1\rm041693\LOCALS~1\Temp\CoyoteAdapter.java-revBASE.svn001.tmp.java Do Jun 10 22:22:20 2010 +++ D:\tomcat\TOMCAT_6_0_26\java\org\apache\catalina\connector\CoyoteAdapter.java Mo Jun 7 17:30:23 2010 @@ -215,7 +215,9 @@ //CometEvent.close was called during an event. request.getEvent().setEventType(CometEvent.EventType.END); request.getEvent().setEventSubType(null); - error = true; + // don't set the error flag - otherwise the socket will be closed + // whenever CometEvent.close is called during the event + // error = true; connector.getContainer().getPipeline().getFirst().event(request, response, request.getEvent()); } res.action(ActionCode.ACTION_COMET_END, null); > > Best regards, > Konstantin Kolinko > Regards, Matthias --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org