Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 37536 invoked from network); 1 Jul 2009 20:13:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 1 Jul 2009 20:13:29 -0000 Received: (qmail 83735 invoked by uid 500); 1 Jul 2009 20:13:39 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 83653 invoked by uid 500); 1 Jul 2009 20:13:39 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 83631 invoked by uid 99); 1 Jul 2009 20:13:36 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Jul 2009 20:13:36 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Jul 2009 20:13:33 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2114A2388898; Wed, 1 Jul 2009 20:13:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r790357 - in /commons/sandbox/runtime/trunk/src: main/java/org/apache/commons/runtime/ main/native/include/ main/native/shared/ main/native/test/ test/org/apache/commons/runtime/ Date: Wed, 01 Jul 2009 20:13:11 -0000 To: commits@commons.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090701201312.2114A2388898@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mturk Date: Wed Jul 1 20:13:11 2009 New Revision: 790357 URL: http://svn.apache.org/viewvc?rev=790357&view=rev Log: Add descriptor attach for reusing Descriptor objects Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c commons/sandbox/runtime/trunk/src/main/native/test/testcase.c commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java?rev=790357&r1=790356&r2=790357&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java Wed Jul 1 20:13:11 2009 @@ -79,6 +79,7 @@ { IERRNUM = 0; IDFLAGS = v; + CONTEXT = null; } private native void close0() Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h?rev=790357&r1=790356&r2=790357&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h Wed Jul 1 20:13:11 2009 @@ -69,12 +69,24 @@ * @param i Native integer descriptor to wrap into Descriptor class * @param p Native pointer descriptor to wrap into Descriptor class * @param cb handler function to use - * @param ho handler function to use */ ACR_DECLARE(jobject) ACR_DescriptorCreate(JNIEnv *env, int f, int i, void *p, acr_descriptor_handler_fn_t *cb); /** + * Attach native descriptor to existing Descriptor object + * @param env Current JNI environment + * @param obj Existing descriptor object + * @param f Descriptor flags. + * @param i Native integer descriptor to wrap into Descriptor class + * @param p Native pointer descriptor to wrap into Descriptor class + * @param cb handler function to use + */ +ACR_DECLARE(int) ACR_DescriptorAttach(JNIEnv *env, jobject obj, + int f, int i, void *p, + acr_descriptor_handler_fn_t *cb); + +/** * Create new Descriptor array * @param env Current JNI environment * @param len Size of the new Descriptor array @@ -171,3 +183,4 @@ #endif #endif /* _ACR_DESCRIPTOR_H */ + Modified: commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c?rev=790357&r1=790356&r2=790357&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c Wed Jul 1 20:13:11 2009 @@ -229,6 +229,30 @@ } } +ACR_DECLARE(int) ACR_DescriptorAttach(JNIEnv *_E, jobject dp, + int f, int i, void *p, + acr_descriptor_handler_fn_t *c) +{ + if (_clazzn.i && J4MID(0000)) { + if ((*_E)->MonitorEnter(_E, dp)) { + /* Object locking failed */ + return ACR_ENOLOCK; + } + SET_IFIELD_I(0000, dp, i); + SET_IFIELD_P(0001, dp, p); + SET_IFIELD_P(0002, dp, c); + SET_IFIELD_P(0003, dp, 0); + SET_IFIELD_P(0004, dp, f); + SET_IFIELD_O(0005, dp, NULL); + + (*_E)->MonitorExit(_E, dp); + return ACR_SUCCESS; + } + else { + return ACR_ECLASSNOTFOUND; + } +} + ACR_DECLARE(int) ACR_DescriptorCleanup(ACR_JNISTDARGS) { if (_clazzn.i && J4MID(0000)) { Modified: commons/sandbox/runtime/trunk/src/main/native/test/testcase.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testcase.c?rev=790357&r1=790356&r2=790357&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Wed Jul 1 20:13:11 2009 @@ -259,6 +259,12 @@ return ACR_DescriptorCreate(_E, ACR_DT_SOCKET, i, I2P(d, void *), dhandler); } +ACR_JNI_EXPORT_DECLARE(jint, TestPrivate, test037)(ACR_JNISTDARGS, jobject d, jint i, jint p) +{ + + return ACR_DescriptorAttach(_E, d, ACR_DT_FILE, i, I2P(p, void *), dhandler); +} + ACR_JNI_EXPORT_DECLARE(jint, TestPrivate, test022)(ACR_JNISTDARGS, jobject d) { Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java?rev=790357&r1=790356&r2=790357&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java (original) +++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java Wed Jul 1 20:13:11 2009 @@ -86,6 +86,7 @@ private static native int test034(Descriptor p); private static native int test035(Class c); private static native String test036(Class c); + private static native int test037(Descriptor d, int i, int p); private static native String test100(String s); @@ -584,7 +585,7 @@ { Descriptor d = test021(2303, 0); assertNotNull("Descriptor", d); - assertEquals("Type", d.getType(), DescriptorType.SOCKET); + assertEquals("Type", DescriptorType.SOCKET, d.getType()); d.close(); d = null; System.gc(); @@ -608,6 +609,24 @@ Thread.sleep(200); } + public void testDescriptorAttach() + throws Throwable + { + Descriptor d = test021(2303, 0); + assertNotNull("Descriptor", d); + assertEquals("Type", DescriptorType.SOCKET, d.getType()); + d.close(); + int r = test037(d, 1964, 0xcafebabe); + assertEquals("Fd", d.fd(), 1964); + assertEquals("Type", DescriptorType.FILE, d.getType()); + d.close(); + d = null; + System.gc(); + // This should be enough for a gc + // from Pointer.finalize() + Thread.sleep(200); + } + public void testUtf16String() throws Throwable {