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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to