commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
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 GMT
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
     {



Mime
View raw message