You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by mh...@apache.org on 2007/03/20 16:53:29 UTC
svn commit: r520447 -
/mina/sandbox/mheath/aioj/trunk/src/main/c/org_apache_aio.cpp
Author: mheath
Date: Tue Mar 20 08:53:28 2007
New Revision: 520447
URL: http://svn.apache.org/viewvc?view=rev&rev=520447
Log:
Fixed support for heap ByteBuffers and writes.
Modified:
mina/sandbox/mheath/aioj/trunk/src/main/c/org_apache_aio.cpp
Modified: mina/sandbox/mheath/aioj/trunk/src/main/c/org_apache_aio.cpp
URL: http://svn.apache.org/viewvc/mina/sandbox/mheath/aioj/trunk/src/main/c/org_apache_aio.cpp?view=diff&rev=520447&r1=520446&r2=520447
==============================================================================
--- mina/sandbox/mheath/aioj/trunk/src/main/c/org_apache_aio.cpp (original)
+++ mina/sandbox/mheath/aioj/trunk/src/main/c/org_apache_aio.cpp Tue Mar 20 08:53:28 2007
@@ -359,7 +359,7 @@
jobject doReadWrite(JNIEnv *env, jobject channel, jobject buffer, jlong position, int flag)
{
- jclass bufferClass = env->GetObjectClass(buffer);
+ jclass bufferClass = env->GetObjectClass(buffer);
// Get buffer limit and position
jint bufferPosition = getByteBufferPosition(env, buffer, bufferClass);
@@ -386,11 +386,21 @@
req->buffers[0].allocatedBufferSize = bufferSizeToAllocate;
if (address == NULL) {
address = getBufferAddress(req, 0);
+
+ // Copy contents of Byte Buffer to address
+ if (byteBufferHasArray(env, buffer, bufferClass)) {
+ jbyteArray array = getByteBufferArray(env, buffer, bufferClass);
+ jbyte *arrayPtr = (jbyte *)env->GetPrimitiveArrayCritical(array, NULL);
+ memcpy(address, arrayPtr, bufferSize);
+ env->ReleasePrimitiveArrayCritical(array, arrayPtr, 0);
+ env->DeleteLocalRef(array);
+ } else {
+ // TODO: Handle byte buffers that don't support arrays
+ LOG_DEBUG("Buffer does not have array\n");
+ }
}
req->buffers[0].buffer = address;
- // TODO: If doing write with heap buffer, copy data from byteBuffer to allocated space
-
// Create future object
jobject future = createPosixReadWriteAioFuture(env, channel, req, buffer, position);
req->future = env->NewGlobalRef(future);
@@ -440,6 +450,8 @@
cleanupPosixAio(env, req);
env->ThrowNew(aioException, "error issuing aio_read request");
}
+ // Advance byteBuffer position
+ setByteBufferPosition(env, buffer, bufferClass, bufferSize);
} else {
LOG_DEBUG("Oops doing nothing\n");
// Throw exception