You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by fh...@apache.org on 2006/07/10 16:20:00 UTC

svn commit: r420538 - in /tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11: InternalNioInputBuffer.java InternalNioOutputBuffer.java

Author: fhanik
Date: Mon Jul 10 07:20:00 2006
New Revision: 420538

URL: http://svn.apache.org/viewvc?rev=420538&view=rev
Log:
since we are writing on a piggy back thread, better make it thread safe in case there are multiple backend threads writing (async or comet)

Modified:
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java

Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java?rev=420538&r1=420537&r2=420538&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java Mon Jul 10 07:20:00 2006
@@ -542,7 +542,7 @@
      * Perform blocking read with a timeout if desired
      * @param timeout boolean - set to true if the system will time out
      * @return boolean - true if data was read, false is EOF is reached
-     * @throws IOException
+     * @throws IOException 
      */
     private boolean readSocket(boolean timeout) throws IOException {
         int nRead = 0;

Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java?rev=420538&r1=420537&r2=420538&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java Mon Jul 10 07:20:00 2006
@@ -394,25 +394,18 @@
         if (!committed) {
             //Socket.send(socket, Constants.ACK_BYTES, 0, Constants.ACK_BYTES.length) < 0
             ByteBuffer buf = ByteBuffer.wrap(Constants.ACK_BYTES,0,Constants.ACK_BYTES.length);    
-            writeToSocket(buf);
+            writeToSocket(buf,false);
         }
 
     }
 
-    private void writeToSocket(ByteBuffer bytebuffer) throws IOException {
+    private synchronized void writeToSocket(ByteBuffer bytebuffer, boolean flip) throws IOException {
         int limit = bytebuffer.position();
-        bytebuffer.rewind();
-        bytebuffer.limit(limit);
-        int remaining = limit;
-        while ( remaining > 0 ) {
+        if ( flip ) bytebuffer.flip();
+        while ( bytebuffer.hasRemaining() ) {
             int written = socket.write(bytebuffer);
-            remaining -= written;
         }
         bbuf.clear();
-        bbuf.rewind();
-        bbuf.limit(bbufLimit);
-
-        //System.out.println("Written:"+limit);
         this.total = 0;
     } 
 
@@ -735,7 +728,7 @@
 
         //write to the socket, if there is anything to write
         if (bbuf.position() > 0) {
-            writeToSocket(bbuf);
+            writeToSocket(bbuf,true);
         }
     }
 



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


Re: svn commit: r420538 - in /tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11: InternalNioInputBuffer.java InternalNioOutputBuffer.java

Posted by Remy Maucherat <re...@apache.org>.
fhanik@apache.org wrote:
> Author: fhanik
> Date: Mon Jul 10 07:20:00 2006
> New Revision: 420538
> 
> URL: http://svn.apache.org/viewvc?rev=420538&view=rev
> Log:
> since we are writing on a piggy back thread, better make it thread safe in case there are multiple backend threads writing (async or comet)
>

I consider this is not a valid use case: none of the objects provided by 
the servlet API are thread safe either, so it's up to the user to sync 
as appropriate. I think the only thing we should guarantee is to not 
call two methods (like two read) in parallel threads. Ok, it is a little 
bit obvious.

Rémy

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