You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2012/11/24 19:49:00 UTC

svn commit: r1413237 - in /tomcat/trunk: java/org/apache/coyote/http11/upgrade/UpgradeServletInputStream.java java/org/apache/coyote/http11/upgrade/UpgradeServletOutputStream.java test/org/apache/coyote/http11/upgrade/TestUpgrade.java

Author: markt
Date: Sat Nov 24 18:48:59 2012
New Revision: 1413237

URL: http://svn.apache.org/viewvc?rev=1413237&view=rev
Log:
Simplify as there are some things that can't happen with HTTP upgrade
than can with a normal HTTP connection (because the protocol tells you
where the end of the request is).

Modified:
    tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeServletInputStream.java
    tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeServletOutputStream.java
    tomcat/trunk/test/org/apache/coyote/http11/upgrade/TestUpgrade.java

Modified: tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeServletInputStream.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeServletInputStream.java?rev=1413237&r1=1413236&r2=1413237&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeServletInputStream.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeServletInputStream.java Sat Nov 24 18:48:59 2012
@@ -23,8 +23,6 @@ import javax.servlet.ServletInputStream;
 
 public abstract class UpgradeServletInputStream extends ServletInputStream {
 
-    private volatile boolean finished = false;
-
     // Start in blocking-mode
     private volatile Boolean ready = Boolean.TRUE;
     private volatile ReadListener listener = null;
@@ -32,12 +30,14 @@ public abstract class UpgradeServletInpu
 
     @Override
     public final boolean isFinished() {
-        return finished;
+        // The only way to finish an HTTP Upgrade connection is to close the
+        // socket.
+        return false;
     }
 
 
     @Override
-    public boolean isReady() {
+    public final boolean isReady() {
         // If we already know the current state, return it.
         if (ready != null) {
             return ready.booleanValue();
@@ -53,7 +53,7 @@ public abstract class UpgradeServletInpu
 
 
     @Override
-    public void setReadListener(ReadListener listener) {
+    public final void setReadListener(ReadListener listener) {
         if (listener == null) {
             // TODO i18n
             throw new IllegalArgumentException();
@@ -73,7 +73,7 @@ public abstract class UpgradeServletInpu
 
 
     @Override
-    public int readLine(byte[] b, int off, int len) throws IOException {
+    public final int readLine(byte[] b, int off, int len) throws IOException {
         preReadChecks();
 
         if (len <= 0) {
@@ -93,7 +93,7 @@ public abstract class UpgradeServletInpu
 
 
     @Override
-    public int read(byte[] b, int off, int len) throws IOException {
+    public final int read(byte[] b, int off, int len) throws IOException {
         preReadChecks();
 
         return doRead(listener == null, b, off, len);
@@ -111,17 +111,17 @@ public abstract class UpgradeServletInpu
 
 
     private int readInternal() throws IOException {
-        // Handles difference between EOF and NO DATA when reading a single byte
+        // Single byte reads for non-blocking need special handling so all
+        // single byte reads run through this method.
         ReadListener readListener = this.listener;
         byte[] b = new byte[1];
         int result = doRead(readListener == null, b, 0, 1);
         if (result == 0) {
             return -1;
         } else if (result == -1) {
-            finished = true;
-            if (readListener != null) {
-                readListener.onAllDataRead();
-            }
+            // Will never happen with a network socket. An IOException will be
+            // thrown when the client closes the connection.
+            // Echo back the -1 to be safe.
             return -1;
         } else {
             return b[0] & 0xFF;
@@ -129,7 +129,7 @@ public abstract class UpgradeServletInpu
     }
 
 
-    protected void onDataAvailable() {
+    protected final void onDataAvailable() {
         ready = Boolean.TRUE;
         listener.onDataAvailable();
     }

Modified: tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeServletOutputStream.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeServletOutputStream.java?rev=1413237&r1=1413236&r2=1413237&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeServletOutputStream.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeServletOutputStream.java Sat Nov 24 18:48:59 2012
@@ -28,12 +28,12 @@ public abstract class UpgradeServletOutp
     private byte[] buffer;
 
     @Override
-    public boolean canWrite() {
+    public final boolean canWrite() {
         return buffer == null;
     }
 
     @Override
-    public void setWriteListener(WriteListener listener) {
+    public final void setWriteListener(WriteListener listener) {
         if (listener == null) {
             // TODO i18n
             throw new IllegalArgumentException();
@@ -84,7 +84,7 @@ public abstract class UpgradeServletOutp
     }
 
 
-    protected void onWritePossible() {
+    protected final void onWritePossible() {
         try {
             writeInternal(buffer, 0, buffer.length);
         } catch (IOException ioe) {

Modified: tomcat/trunk/test/org/apache/coyote/http11/upgrade/TestUpgrade.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http11/upgrade/TestUpgrade.java?rev=1413237&r1=1413236&r2=1413237&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/coyote/http11/upgrade/TestUpgrade.java (original)
+++ tomcat/trunk/test/org/apache/coyote/http11/upgrade/TestUpgrade.java Sat Nov 24 18:48:59 2012
@@ -92,7 +92,10 @@ public class TestUpgrade extends TomcatB
 
         // Note: BufferedReader.readLine() strips new lines
         //       ServletInputStream.readLine() does not strip new lines
-        Assert.assertEquals(MESSAGE, response );
+        Assert.assertEquals(MESSAGE, response);
+        Assert.assertEquals(MESSAGE, response);
+
+        pw.close();
     }
 
 
@@ -245,7 +248,7 @@ public class TestUpgrade extends TomcatB
 
             @Override
             public void onAllDataRead() {
-                System.out.println("All data read");
+                // NO-OP for HTTP Upgrade
             }
 
             @Override



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