tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1477946 - in /tomcat/trunk/java/org/apache/catalina/connector: CoyoteOutputStream.java LocalStrings.properties OutputBuffer.java
Date Wed, 01 May 2013 10:50:09 GMT
Author: markt
Date: Wed May  1 10:50:08 2013
New Revision: 1477946

URL: http://svn.apache.org/r1477946
Log:
Limit to one non-blocking write at a time.

Modified:
    tomcat/trunk/java/org/apache/catalina/connector/CoyoteOutputStream.java
    tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java

Modified: tomcat/trunk/java/org/apache/catalina/connector/CoyoteOutputStream.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/CoyoteOutputStream.java?rev=1477946&r1=1477945&r2=1477946&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/CoyoteOutputStream.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/CoyoteOutputStream.java Wed May  1 10:50:08
2013
@@ -21,18 +21,21 @@ import java.io.IOException;
 import javax.servlet.ServletOutputStream;
 import javax.servlet.WriteListener;
 
+import org.apache.tomcat.util.res.StringManager;
+
 /**
  * Coyote implementation of the servlet output stream.
  *
  * @author Costin Manolache
  * @author Remy Maucherat
  */
-public class CoyoteOutputStream
-    extends ServletOutputStream {
+public class CoyoteOutputStream extends ServletOutputStream {
 
+    protected static final StringManager sm =
+            StringManager.getManager(Constants.Package);
 
-    // ----------------------------------------------------- Instance Variables
 
+    // ----------------------------------------------------- Instance Variables
 
     protected OutputBuffer ob;
 
@@ -73,26 +76,33 @@ public class CoyoteOutputStream
 
 
     @Override
-    public void write(int i)
-        throws IOException {
+    public void write(int i) throws IOException {
+        checkNonBlockingWrite();
         ob.writeByte(i);
     }
 
 
     @Override
-    public void write(byte[] b)
-        throws IOException {
+    public void write(byte[] b) throws IOException {
         write(b, 0, b.length);
     }
 
 
     @Override
-    public void write(byte[] b, int off, int len)
-        throws IOException {
+    public void write(byte[] b, int off, int len) throws IOException {
+        checkNonBlockingWrite();
         ob.write(b, off, len);
     }
 
 
+    private void checkNonBlockingWrite() {
+        if (!ob.isBlocking() && !ob.isReady()) {
+            throw new IllegalStateException(
+                    sm.getString("coyoteOutputStream.nbNotready"));
+        }
+    }
+
+
     /**
      * Will send the buffer to the client.
      */

Modified: tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties?rev=1477946&r1=1477945&r2=1477946&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties Wed May  1 10:50:08
2013
@@ -29,6 +29,8 @@ coyoteConnector.protocolHandlerPauseFail
 coyoteConnector.protocolHandlerResumeFailed=Protocol handler resume failed
 coyoteConnector.parseBodyMethodNoTrace=TRACE method MUST NOT include an entity (see RFC 2616
Section 9.6)
 
+coyoteOutputStream.nbNotready=In non-blocking mode you may not write to the ServletOutputStream
until the previous write has completed and isReady() returns true
+
 coyoteRequest.getInputStream.ise=getReader() has already been called for this request
 coyoteRequest.getReader.ise=getInputStream() has already been called for this request
 coyoteRequest.sessionCreateCommitted=Cannot create a session after the response has been
committed

Modified: tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java?rev=1477946&r1=1477945&r2=1477946&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java Wed May  1 10:50:08
2013
@@ -659,4 +659,9 @@ public class OutputBuffer extends Writer
     public void setWriteListener(WriteListener listener) {
         coyoteResponse.setWriteListener(listener);
     }
+
+
+    public boolean isBlocking() {
+        return coyoteResponse.getWriteListener() == null;
+    }
 }



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


Mime
View raw message