- New read loop (much more conventional using the more accurate InputStream.available...
authorremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 30 Apr 2007 23:36:10 +0000 (23:36 +0000)
committerremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 30 Apr 2007 23:36:10 +0000 (23:36 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@533881 13f79535-47bb-0310-9956-ffa450edef68

webapps/examples/WEB-INF/classes/chat/ChatServlet.java

index f27c3c0..a306bed 100644 (file)
@@ -149,16 +149,18 @@ public class ChatServlet
         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)