tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Filip Hanik - Dev Lists <devli...@hanik.com>
Subject Re: svn commit: r533881 - /tomcat/tc6.0.x/trunk/webapps/examples/WEB-INF/classes/chat/ChatServlet.java
Date Tue, 01 May 2007 14:42:34 GMT
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()?

Filip

remm@apache.org wrote:
> Author: remm
> Date: Mon Apr 30 16:36:10 2007
> New Revision: 533881
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=533881
> Log:
> - New read loop (much more conventional using the more accurate InputStream.available()
method).
>
> Modified:
>     tomcat/tc6.0.x/trunk/webapps/examples/WEB-INF/classes/chat/ChatServlet.java
>
> Modified: tomcat/tc6.0.x/trunk/webapps/examples/WEB-INF/classes/chat/ChatServlet.java
> URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/examples/WEB-INF/classes/chat/ChatServlet.java?view=diff&rev=533881&r1=533880&r2=533881
> ==============================================================================
> --- tomcat/tc6.0.x/trunk/webapps/examples/WEB-INF/classes/chat/ChatServlet.java (original)
> +++ tomcat/tc6.0.x/trunk/webapps/examples/WEB-INF/classes/chat/ChatServlet.java Mon Apr
30 16:36:10 2007
> @@ -149,16 +149,18 @@
>          throws IOException, ServletException {
>          InputStream is = request.getInputStream();
>          byte[] buf = new byte[512];
> -        do {
> +        while (is.available() > 0) {
> +            log("Available: " + is.available());
>              int n = is.read(buf);
>              if (n > 0) {
>                  log("Read " + n + " bytes: " + new String(buf, 0, n) 
>                          + " for session: " + request.getSession(true).getId());
>              } else if (n < 0) {
> -                error(event, request, response);
> +                log("End of file: " + n);
> +                end(event, request, response);
>                  return;
>              }
> -        } while (is.available() > 0);
> +        }
>      }
>  
>      protected void service(HttpServletRequest request, HttpServletResponse response)
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>
>
>
>   


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


Mime
View raw message