Author: markt
Date: Tue Feb 28 21:20:55 2012
New Revision: 1294837

URL: http://svn.apache.org/viewvc?rev=1294837&view=rev
Log:
Update the upgrade API to support non-blocking reads.
Neither NIO nor APR implements them yet.

Modified:
    tomcat/trunk/java/org/apache/catalina/websocket/WsFrame.java
    tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java
    tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeAprProcessor.java
    tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeBioProcessor.java
    tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeNioProcessor.java
    tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeProcessor.java

Modified: tomcat/trunk/java/org/apache/catalina/websocket/WsFrame.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/WsFrame.java?rev=1294837&r1=1294836&r2=1294837&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/WsFrame.java (original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/WsFrame.java Tue Feb 28 
21:20:55 2012
@@ -155,7 +155,7 @@ public class WsFrame {
         int read = 0;
         int last = 0;
         while (read < bytes.length) {
-            last = processor.read(bytes, read, bytes.length - read);
+            last = processor.read(true, bytes, read, bytes.length - read);
             if (last == -1) {
                 throw new IOException(sm.getString("frame.eos"));
             }

Modified: tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java?rev=1294837&r1=1294836&r2=1294837&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java Tue Feb 
28 21:20:55 2012
@@ -98,7 +98,7 @@ public class WsInputStream extends java.
         if (len > remaining) {
             len = (int) remaining;
         }
-        int result = processor.read(b, off, len);
+        int result = processor.read(true, b, off, len);
         if(result == -1) {
             return -1;
         }

Modified: 
tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeAprProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeAprProcessor.java?rev=1294837&r1=1294836&r2=1294837&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeAprProcessor.java 
(original)
+++ tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeAprProcessor.java 
Tue Feb 28 21:20:55 2012
@@ -71,7 +71,9 @@ public class UpgradeAprProcessor extends
 
 
     @Override
-    public int read(byte[] bytes, int off, int len) throws IOException {
+    public int read(boolean block, byte[] bytes, int off, int len)
+            throws IOException {
+        // TODO support non-blocking reads
         return Socket.recv(socket, bytes, off, len);
     }
 }

Modified: 
tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeBioProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeBioProcessor.java?rev=1294837&r1=1294836&r2=1294837&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeBioProcessor.java 
(original)
+++ tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeBioProcessor.java 
Tue Feb 28 21:20:55 2012
@@ -68,7 +68,10 @@ public class UpgradeBioProcessor extends
 
 
     @Override
-    public int read(byte[] bytes, int off, int len) throws IOException {
+    public int read(boolean block, byte[] bytes, int off, int len)
+            throws IOException {
+        // The BIO endpoint always uses blocking IO so the block parameter is
+        // ignored and a blocking read is performed.
         return inputStream.read(bytes, off, len);
     }
 }

Modified: 
tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeNioProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeNioProcessor.java?rev=1294837&r1=1294836&r2=1294837&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeNioProcessor.java 
(original)
+++ tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeNioProcessor.java 
Tue Feb 28 21:20:55 2012
@@ -102,7 +102,10 @@ public class UpgradeNioProcessor extends
     }
 
     @Override
-    public int read(byte[] bytes, int off, int len) throws IOException {
+    public int read(boolean block, byte[] bytes, int off, int len)
+            throws IOException {
+        // TODO Implement non-blocking reads. Should be as simple as replacing
+        // true with block in the two lines below
         if (len > maxRead) {
             return readSocket(true, bytes, off, maxRead);
         } else {

Modified: 
tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeProcessor.java?rev=1294837&r1=1294836&r2=1294837&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeProcessor.java 
(original)
+++ tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeProcessor.java 
Tue Feb 28 21:20:55 2012
@@ -46,8 +46,32 @@ public abstract class UpgradeProcessor<S
     public abstract void write(byte[] b, int off, int len) throws IOException;
 
     // Input methods
+    /**
+     * This is always a blocking read of a single byte.
+     *
+     * @return  The next byte or -1 if the end of the input is reached.
+     *
+     * @throws IOException  If a problem occurs trying to read from the input
+     */
     public abstract int read() throws IOException;
-    public abstract int read(byte[] bytes, int off, int len) throws 
IOException;
+
+    /**
+     * Read up to len bytes from the input in either blocking or non-blocking
+     * mode (where non-blocking is supported). If the input does not support
+     * non-blocking reads, a blcoking read will be performed.
+     *
+     * @param block
+     * @param bytes
+     * @param off
+     * @param len
+     * @return  The number of bytes read or -1 if the end of the input is
+     *          reached. Non-blocking reads may return zero if no data is
+     *          available. Blocking reads never return zero.
+     *
+     * @throws IOException  If a problem occurs trying to read from the input
+     */
+    public abstract int read(boolean block, byte[] bytes, int off, int len)
+            throws IOException;
 
     @Override
     public final UpgradeInbound getUpgradeInbound() {



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

Reply via email to