tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1478968 - in /tomcat/trunk: java/org/apache/coyote/http11/ test/org/apache/catalina/nonblocking/
Date Fri, 03 May 2013 20:34:34 GMT
Author: markt
Date: Fri May  3 20:34:34 2013
New Revision: 1478968

URL: http://svn.apache.org/r1478968
Log:
Faking of non-blocking reads for BIO.
Tweak test case so it relies more on the Servlet API and less on the implementation details
of the test so BIO's fake blocking passes.

Modified:
    tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java
    tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
    tomcat/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java
    tomcat/trunk/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java

Modified: tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java?rev=1478968&r1=1478967&r2=1478968&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java Fri May  3 20:34:34
2013
@@ -810,6 +810,8 @@ public abstract class AbstractHttp11Proc
             ((AtomicBoolean) param).set(asyncStateMachine.isAsyncTimingOut());
         } else if (actionCode == ActionCode.ASYNC_IS_ERROR) {
             ((AtomicBoolean) param).set(asyncStateMachine.isAsyncError());
+        } else if (actionCode == ActionCode.AVAILABLE) {
+            request.setAvailable(inputBuffer.available());
         } else if (actionCode == ActionCode.NB_WRITE_INTEREST) {
             AtomicBoolean isReady = (AtomicBoolean)param;
             isReady.set(getOutputBuffer().isReady());

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java?rev=1478968&r1=1478967&r2=1478968&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java Fri May  3 20:34:34
2013
@@ -472,9 +472,6 @@ public class Http11NioProcessor extends 
                     log.warn(sm.getString("http11processor.socket.ssl"), e);
                 }
             }
-
-        } else if (actionCode == ActionCode.AVAILABLE) {
-            request.setAvailable(inputBuffer.available());
         } else if (actionCode == ActionCode.COMET_BEGIN) {
             comet = true;
         } else if (actionCode == ActionCode.COMET_END) {

Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java?rev=1478968&r1=1478967&r2=1478968&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java Fri May  3 20:34:34
2013
@@ -71,6 +71,17 @@ public class InternalInputBuffer extends
 
 
     /**
+     * Data is always available for blocking IO (if you wait long enough) so
+     * return a value of 1. Note that the actual value is never used it is only
+     * tested for == 0 or > 0.
+     */
+    @Override
+    public int available() {
+        return 1;
+    }
+
+
+    /**
      * Read the request line. This function is meant to be used during the
      * HTTP request header parsing. Do NOT attempt to read the request body
      * using it.
@@ -543,8 +554,7 @@ public class InternalInputBuffer extends
 
     @Override
     protected int nbRead() throws IOException {
-        // TODO Auto-generated method stub
-        return 0;
+        throw new IllegalStateException("This method is unused for BIO");
     }
 
 

Modified: tomcat/trunk/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java?rev=1478968&r1=1478967&r2=1478968&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java (original)
+++ tomcat/trunk/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java Fri May  3 20:34:34
2013
@@ -57,12 +57,6 @@ public class TestNonBlockingAPI extends 
     public void testNonBlockingRead() throws Exception {
         Tomcat tomcat = getTomcatInstance();
 
-        // TODO Faking non-blocking reads is not yet implemented for BIO.
-        if (tomcat.getConnector().getProtocolHandlerClassName().equals(
-                "org.apache.coyote.http11.Http11Protocol")) {
-            return;
-        }
-
         // TODO Non-blocking reads are not yet implemented for APR.
         if (tomcat.getConnector().getProtocolHandlerClassName().equals(
                 "org.apache.coyote.http11.Http11AprProtocol")) {
@@ -294,12 +288,8 @@ public class TestNonBlockingAPI extends 
             listener = new TestReadListener(actx);
             in.setReadListener(listener);
 
-            while (in.isReady()) {
-                listener.onDataAvailable();
-            }
+            listener.onDataAvailable();
         }
-
-
     }
 
     @WebServlet(asyncSupported = true)
@@ -365,12 +355,16 @@ public class TestNonBlockingAPI extends 
                 ServletInputStream in = ctx.getRequest().getInputStream();
                 String s = "";
                 byte[] b = new byte[8192];
-                while (in.isReady()) {
-                    int read = in.read(b);
+                int read = 0;
+                do {
+                    read = in.read(b);
+                    if (read == -1) {
+                        break;
+                    }
                     s += new String(b, 0, read);
-                }
+                } while (in.isReady());
                 System.out.println(s);
-                if ("FINISHED".equals(s)) {
+                if (s.endsWith("FINISHED")) {
                     ctx.complete();
                     ctx.getResponse().getWriter().print("OK");
                 } else {



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


Mime
View raw message