You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by tr...@apache.org on 2007/11/06 12:23:24 UTC
svn commit: r592376 -
/mina/trunk/core/src/main/java/org/apache/mina/common/CachedBufferAllocator.java
Author: trustin
Date: Tue Nov 6 03:23:13 2007
New Revision: 592376
URL: http://svn.apache.org/viewvc?rev=592376&view=rev
Log:
Fixed two bugs in CachedBufferAllocator
* Big buffer can be returned to the pool, but it can never be borrowed from the pool.
* The limit of the new buffer is incorrect.
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/CachedBufferAllocator.java
Modified: mina/trunk/core/src/main/java/org/apache/mina/common/CachedBufferAllocator.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/CachedBufferAllocator.java?rev=592376&r1=592375&r2=592376&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/common/CachedBufferAllocator.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/common/CachedBufferAllocator.java Tue Nov 6 03:23:13 2007
@@ -92,21 +92,21 @@
}
};
- public IoBuffer allocate(int capacity, boolean direct) {
- capacity = normalizeCapacity(capacity);
+ public IoBuffer allocate(int requestedCapacity, boolean direct) {
+ int actualCapacity = normalizeCapacity(requestedCapacity);
IoBuffer buf ;
- if (capacity > MAX_CACHED_BUFFER_SIZE) {
+ if (actualCapacity > MAX_CACHED_BUFFER_SIZE) {
if (direct) {
- buf = wrap(ByteBuffer.allocateDirect(capacity));
+ buf = wrap(ByteBuffer.allocateDirect(actualCapacity));
} else {
- buf = wrap(ByteBuffer.allocate(capacity));
+ buf = wrap(ByteBuffer.allocate(actualCapacity));
}
} else {
Queue<CachedBuffer> pool;
if (direct) {
- pool = directBuffers.get().get(capacity);
+ pool = directBuffers.get().get(actualCapacity);
} else {
- pool = heapBuffers.get().get(capacity);
+ pool = heapBuffers.get().get(actualCapacity);
}
// Recycle if possible.
@@ -117,12 +117,14 @@
buf.order(ByteOrder.BIG_ENDIAN);
} else {
if (direct) {
- buf = wrap(ByteBuffer.allocateDirect(capacity));
+ buf = wrap(ByteBuffer.allocateDirect(actualCapacity));
} else {
- buf = wrap(ByteBuffer.allocate(capacity));
+ buf = wrap(ByteBuffer.allocate(actualCapacity));
}
}
}
+
+ buf.limit(requestedCapacity);
return buf;
}
@@ -226,6 +228,9 @@
private void free(ByteBuffer oldBuf) {
if (oldBuf == null) {
+ return;
+ }
+ if (oldBuf.capacity() > MAX_CACHED_BUFFER_SIZE) {
return;
}
if (Thread.currentThread() != ownerThread) {