directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r106375 - /incubator/directory/seda/trunk/src/java/org/apache/seda/output/TCPOutputManager.java
Date Wed, 24 Nov 2004 03:35:24 GMT
Author: akarasulu
Date: Tue Nov 23 19:35:22 2004
New Revision: 106375

Modified:
   incubator/directory/seda/trunk/src/java/org/apache/seda/output/TCPOutputManager.java
Log:
Added code to make sure we're writing all the bytes out. We should be using 
the selector with OP_WRITE to determine when we can write to the output buffer
but for now we have a little hack in place.  This needs to be fix at some point
perhaps the refactoring is a good time for this.


Modified: incubator/directory/seda/trunk/src/java/org/apache/seda/output/TCPOutputManager.java
Url: http://svn.apache.org/viewcvs/incubator/directory/seda/trunk/src/java/org/apache/seda/output/TCPOutputManager.java?view=diff&rev=106375&p1=incubator/directory/seda/trunk/src/java/org/apache/seda/output/TCPOutputManager.java&r1=106374&p2=incubator/directory/seda/trunk/src/java/org/apache/seda/output/TCPOutputManager.java&r2=106375
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/output/TCPOutputManager.java	(original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/output/TCPOutputManager.java	Tue
Nov 23 19:35:22 2004
@@ -181,10 +181,16 @@
             return;
         }
 
-        channel.write(buf);
+        // really nasty hack that spins until send buffer clears
+        while ( buf.hasRemaining() )
+        {
+            channel.write(buf);
+        }
+
         monitor.writeOccurred(this, key);
     }
 
+    
     public void write(ClientKey key, ByteBuffer[] buffers)
                throws IOException
     {
@@ -196,8 +202,35 @@
             return;
         }
 
-        channel.write(buffers);
+        // really nasty hack that spins until send buffer clears
+        while( hasMore( buffers ) )
+        {
+            channel.write(buffers);
+        }
+
         monitor.writeOccurred(this, key);
+    }
+
+
+    /**
+     * Used by nasty hack until send buffer clears to flush out all data.  This
+     * should be removed when the hack is no longer a hack and things are
+     * refactored.
+     *
+     * @param buffers the buffers to check for remaining bytes
+     * @return true if there are more to write false otherwise
+     */
+    private boolean hasMore( ByteBuffer[] buffers )
+    {
+        for ( int ii = 0; ii < buffers.length; ii++ )
+        {
+            if ( buffers[ii].hasRemaining() )
+            {
+                return true;
+            }
+        }
+
+        return false;
     }
 
     /**

Mime
View raw message