diff options
author | Rafael H. Schloming <rhs@apache.org> | 2008-08-06 22:44:43 +0000 |
---|---|---|
committer | Rafael H. Schloming <rhs@apache.org> | 2008-08-06 22:44:43 +0000 |
commit | 3cd55ca351e299aea97000006175b6dc7c9698b2 (patch) | |
tree | ac6d0d9ff3119b1922c0e38eadca6b86bcbc96bb /java | |
parent | 03c3f6edb2b17841053250bda46fde1054d32d67 (diff) | |
download | qpid-python-3cd55ca351e299aea97000006175b6dc7c9698b2.tar.gz |
QPID-1222: round up the buffer size to the nearest power of two
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@683437 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
-rw-r--r-- | java/common/src/main/java/org/apache/qpid/transport/network/io/IoSender.java | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/java/common/src/main/java/org/apache/qpid/transport/network/io/IoSender.java b/java/common/src/main/java/org/apache/qpid/transport/network/io/IoSender.java index 7ac5649e99..23f48a06de 100644 --- a/java/common/src/main/java/org/apache/qpid/transport/network/io/IoSender.java +++ b/java/common/src/main/java/org/apache/qpid/transport/network/io/IoSender.java @@ -61,7 +61,7 @@ final class IoSender extends Thread implements Sender<ByteBuffer> { 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 @@ final class IoSender extends Thread implements Sender<ByteBuffer> 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 @@ final class IoSender extends Thread implements Sender<ByteBuffer> { 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 @@ final class IoSender extends Thread implements Sender<ByteBuffer> 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)); |