tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Remy Maucherat <r...@apache.org>
Subject Re: svn commit: r533881 - /tomcat/tc6.0.x/trunk/webapps/examples/WEB-INF/classes/chat/ChatServlet.java
Date Tue, 01 May 2007 15:10:39 GMT
Filip Hanik - Dev Lists wrote:
> question about this one,
> since a client disconnect is signaled by a READ for the NIO connector, 
> and the only way to find out if the client was disconnected, the 
> InputStream.read() is supposed to return -1, how does that work with the 
> is.available()?

For a client disconnect, you'll get an IO exception during the read, not 
a -1. The only situation where you'll get a -1 (that I know about) is 
for the end of the request body, for example if the content-length 
header says 10, and 10 bytes of the body have been read (so bytes may 
still be available on the socket, but they belong to the next request). 
Ideally, there would be a way to detect a disconnect in the poller so 
that the correct event is sent (this would avoid most IO exceptions, 
which is IMO much cleaner and more efficient).

I understand available() as "there's something to read, and it won't 
block". It also allows enforcing the rule saying that the servlet must 
read all the stuff that is available when it gets a read event, which 
doesn't hurt.

Rémy

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


Mime
View raw message