qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject svn commit: r683437 - /incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/network/io/IoSender.java
Date Wed, 06 Aug 2008 22:44:44 GMT
Author: rhs
Date: Wed Aug  6 15:44:43 2008
New Revision: 683437

URL: http://svn.apache.org/viewvc?rev=683437&view=rev
Log:
QPID-1222: round up the buffer size to the nearest power of two

Modified:
    incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/network/io/IoSender.java

Modified: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/network/io/IoSender.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/network/io/IoSender.java?rev=683437&r1=683436&r2=683437&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/network/io/IoSender.java
(original)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/transport/network/io/IoSender.java
Wed Aug  6 15:44:43 2008
@@ -61,7 +61,7 @@
     {
         this.transport = transport;
         this.socket = transport.getSocket();
-        this.buffer = new byte[bufferSize];
+        this.buffer = new byte[pof2(bufferSize)]; // buffer size must be a power of 2
         this.timeout = timeout;
 
         try
@@ -78,6 +78,16 @@
         start();
     }
 
+    private static final int pof2(int n)
+    {
+        int result = 1;
+        while (result < n)
+        {
+            result *= 2;
+        }
+        return result;
+    }
+
     private static final int mod(int n, int m)
     {
         int r = n % m;
@@ -106,7 +116,7 @@
                 {
                     long start = System.currentTimeMillis();
                     long elapsed = 0;
-                    while (head - tail >= size && elapsed < timeout)
+                    while (!closed.get() && head - tail >= size && elapsed
< timeout)
                     {
                         try
                         {
@@ -119,6 +129,11 @@
                         elapsed += System.currentTimeMillis() - start;
                     }
 
+                    if (closed.get())
+                    {
+                        throw new TransportException("sender is closed", exception);
+                    }
+
                     if (head - tail >= size)
                     {
                         throw new TransportException(String.format("write timed out: %s,
%s", head, tail));



Mime
View raw message