commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1135690 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/io/ java/org/apache/commons/runtime/net/ native/include/acr/ native/os/unix/ native/shared/
Date Tue, 14 Jun 2011 16:43:19 GMT
Author: mturk
Date: Tue Jun 14 16:43:18 2011
New Revision: 1135690

URL: http://svn.apache.org/viewvc?rev=1135690&view=rev
Log:
Rewrite the descriptor base type from int to long which is pointer to native struct

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Descriptor.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalDescriptor.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Poll.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/PosixSelector.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java
    commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/netapi.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/selector.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c
    commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c
    commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Descriptor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Descriptor.java?rev=1135690&r1=1135689&r2=1135690&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Descriptor.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Descriptor.java
Tue Jun 14 16:43:18 2011
@@ -20,6 +20,7 @@ import java.io.Closeable;
 import java.io.Flushable;
 import java.io.IOException;
 import java.io.SyncFailedException;
+import org.apache.commons.runtime.util.Utils;
 
 /** Represents the Operating System object descriptor.
  * <p>
@@ -38,18 +39,14 @@ public abstract class Descriptor impleme
 
     /** Operating system descriptor.
      */
-    protected int       fd;
-    /** Descriptor context.
-     */
-    protected Object    ad;
+    protected long     fd;
 
     /**
      * Creates a new object.
      */
     protected  Descriptor()
     {
-        fd = -1;
-        ad = null;
+        fd = 0L;
     }
 
     private static native void init0();
@@ -121,7 +118,7 @@ public abstract class Descriptor impleme
     {
         // true if both int is negative or zero
         // Descriptor is always assured to be above the stderr (#3)
-        if (fd == -1 || fd == 0)
+        if (fd == 0L)
             return false;
         else
             return true;
@@ -134,7 +131,7 @@ public abstract class Descriptor impleme
      */
     public final boolean closed()
     {
-        if (fd == -1 || fd == 0)
+        if (fd == 0L)
             return true;
         else
             return false;
@@ -144,34 +141,12 @@ public abstract class Descriptor impleme
      * Get underlying Operating system descriptor.
      * @return operating system descriptor.
      */
-    public final int fd()
+    public final long fd()
     {
         return fd;
     }
 
     /**
-     * Get this descriptor's context.
-     * @return descriptor context.
-     */
-    public final Object attachment()
-    {
-        return ad;
-    }
-
-    /**
-     * Attaches the given object to this descriptor.
-     *
-     * @return the previously attached descriptor context, if any,
-     *         otherwise {@code null}.
-     */
-    public final Object attach(Object ctx)
-    {
-        Object org = ad;
-        ad = ctx;
-        return org;
-    }
-
-    /**
      * Compares this {@code Descriptor} to the specified object.
      *
      * @param other a {@code Descriptor}
@@ -206,7 +181,7 @@ public abstract class Descriptor impleme
     public String toString()
     {
         if (fd >= 0) {
-            return "#" + Integer.toString(fd);
+            return "#" + Utils.hex(fd);
         }
         else {
             return "(nil)";

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalDescriptor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalDescriptor.java?rev=1135690&r1=1135689&r2=1135690&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalDescriptor.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalDescriptor.java
Tue Jun 14 16:43:18 2011
@@ -36,12 +36,12 @@ import org.apache.commons.runtime.io.Des
  */
 final class LocalDescriptor extends Descriptor
 {
-    private static native int     close0(int fd);
-    private static native int     sendz0(int fd);
-    private static native int     socket0(int type, boolean blocking)
+    private static native int     close0(long fd);
+    private static native int     sendz0(long fd);
+    private static native long    socket0(int type, boolean blocking)
         throws IOException;
-    private static native int     block0(int fd, boolean block);
-    private static native boolean isBlocking0(int fd)
+    private static native int     block0(long fd, boolean block);
+    private static native boolean isBlocking0(long fd)
         throws IOException;
 
     private boolean               xclosed = false;
@@ -50,7 +50,7 @@ final class LocalDescriptor extends Desc
     {
     }
 
-    public LocalDescriptor(int fd)
+    public LocalDescriptor(long fd)
     {
         this.fd = fd;
     }
@@ -105,7 +105,7 @@ final class LocalDescriptor extends Desc
         xclosed = true;
         if (valid()) {
             int rc = close0(fd);
-            fd     = -1;
+            fd     = 0L;
             if (rc != 0)
                 throw new SocketException(Status.describe(rc));
         }
@@ -155,7 +155,7 @@ final class LocalDescriptor extends Desc
                 // Ignore exceptions during close
             }
             finally {
-                fd = -1;
+                fd = 0L;
             }
         }
     }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java?rev=1135690&r1=1135689&r2=1135690&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java
Tue Jun 14 16:43:18 2011
@@ -46,7 +46,7 @@ public class LocalEndpoint extends Endpo
     private SelectionKeyImpl            key;
     private boolean                     connected = false;
 
-    private static native int           connect0(int fd, byte[] sa, int timeout);
+    private static native int           connect0(long fd, byte[] sa, int timeout);
 
     /**
      * Creates a new unconnected socket object.

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java?rev=1135690&r1=1135689&r2=1135690&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java
Tue Jun 14 16:43:18 2011
@@ -154,8 +154,8 @@ public class LocalServerEndpoint extends
         return key.queue(ops);
     }
 
-    private static native int           bind0(int fd, byte[] sa, int backlog);
-    private static native int           accept0(int fd, byte[] sa, boolean block)
+    private static native int           bind0(long fd, byte[] sa, int backlog);
+    private static native long          accept0(long fd, byte[] sa, boolean block)
         throws SocketException;
 
     @Override
@@ -183,7 +183,7 @@ public class LocalServerEndpoint extends
     {
         if (sd.closed())
             throw new ClosedDescriptorException();
-        int fd = accept0(sd.fd(), sa.sockaddr(), blocking);
+        long fd = accept0(sd.fd(), sa.sockaddr(), blocking);
         LocalDescriptor ad = new LocalDescriptor(fd);
         return new LocalEndpoint(ad, sa);
     }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Poll.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Poll.java?rev=1135690&r1=1135689&r2=1135690&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Poll.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Poll.java Tue
Jun 14 16:43:18 2011
@@ -68,18 +68,19 @@ public final class Poll
     public static final short     POLLTTL       = 0x0400;
 
 
-    private static native int wait0(int[] fds, short[] events, short[] revents,
+    private static native int wait0(long[] fds, short[] events, short[] revents,
                                     int nelts, int timeout)
-        throws OutOfMemoryError, InvalidArgumentException,
+        throws OutOfMemoryError,
+               InvalidArgumentException,
                InvalidDescriptorException;
-    private static native short wait1(int fd, short events, int timeout);
+    private static native short wait1(long fd, short events, int timeout);
 
-    private static short wait(int fd, short events, int timeout)
+    private static short wait(long fd, short events, int timeout)
         throws OutOfMemoryError,
                InvalidArgumentException,
                InvalidDescriptorException
     {
-        if (fd == -1 || (fd >= 0 && fd <= 3))
+        if (fd == 0L)
             throw new InvalidDescriptorException();
         if ((events & 0x00ff) == 0)
             throw new InvalidArgumentException();

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/PosixSelector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/PosixSelector.java?rev=1135690&r1=1135689&r2=1135690&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/PosixSelector.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/PosixSelector.java
Tue Jun 14 16:43:18 2011
@@ -51,8 +51,8 @@ final class PosixSelector extends Abstra
     private static native void  wakeup0(long pollset);
     private static native int   destroy0(long pollset);
     private static native int   size0(long pollset);
-    private static native int   add0(long pollset, SelectionKeyImpl key, int fd, int events,
int ttl);
-    private static native int   del0(long pollset, SelectionKeyImpl key, int fd);
+    private static native int   add0(long pollset, SelectionKeyImpl key, long fd, int events,
int ttl);
+    private static native int   del0(long pollset, SelectionKeyImpl key, long fd);
     private static native int   clr0(long pollset, SelectionKeyImpl[] set);
     private static native int   wait0(long pollset, SelectionKeyImpl[] set, short[] events,
                                       int timeout, boolean autocancel);

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java?rev=1135690&r1=1135689&r2=1135690&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java
Tue Jun 14 16:43:18 2011
@@ -33,12 +33,12 @@ import org.apache.commons.runtime.io.Des
 final class SocketDescriptor extends Descriptor
 {
 
-    private static native int     close0(int fd);
-    private static native int     sendz0(int fd);
-    private static native int     socket0(int type)
+    private static native int     close0(long fd);
+    private static native int     sendz0(long fd);
+    private static native long    socket0(int type)
         throws IOException;
-    private static native int     block0(int fd, boolean block);
-    private static native boolean isBlocking0(int fd)
+    private static native int     block0(long fd, boolean block);
+    private static native boolean isBlocking0(long fd)
         throws IOException;
 
     private boolean xclosed = false;
@@ -47,7 +47,7 @@ final class SocketDescriptor extends Des
     {
     }
 
-    public SocketDescriptor(int fd)
+    public SocketDescriptor(long fd)
     {
         this.fd = fd;
     }
@@ -96,7 +96,7 @@ final class SocketDescriptor extends Des
         xclosed = true;
         if (valid()) {
             int rc = close0(fd);
-            fd     = -1;
+            fd     = 0L;
             if (rc != 0)
                 throw new SocketException(Status.describe(rc));
         }
@@ -146,7 +146,7 @@ final class SocketDescriptor extends Des
                 // Ignore exceptions during close
             }
             finally {
-                fd = -1;
+                fd = 0L;
             }
         }
     }

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=1135690&r1=1135689&r2=1135690&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 Tue Jun 14 16:43:18
2011
@@ -19,18 +19,32 @@
 
 #include "acr/jniapi.h"
 
+typedef struct acr_fd_t acr_fd_t;
+struct acr_fd_t {
+    int         type;   /**< Descriptor type */
+    int         size;   /**< Allocated descriptor size */
+    union {
+        jlong   nh;
+        void    *p;
+        int      f;
+#if defined(WINDOWS)
+        HANDLE   h;
+        SOCKET   s;
+#else
+        int      h;
+        int      s;
+#endif
+    } u;
+};
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-int
+acr_fd_t *
 AcrGetDescriptorFd(JNI_STDARGS);
 int
-AcrSetDescriptorFd(JNI_STDARGS, int fd);
-jobject
-AcrGetDescriptorCtx(JNI_STDARGS);
-int
-AcrSetDescriptorCtx(JNI_STDARGS, jobject ob);
+AcrSetDescriptorFd(JNI_STDARGS, acr_fd_t *fd);
 
 #ifdef __cplusplus
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/netapi.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/netapi.h?rev=1135690&r1=1135689&r2=1135690&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/netapi.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/netapi.h Tue Jun 14 16:43:18
2011
@@ -20,6 +20,7 @@
 #include "acr/stdtypes.h"
 #include "acr/jnidefs.h"
 #include "acr/netdefs.h"
+#include "acr/descriptor.h"
 
 typedef struct acr_sockaddr_t acr_sockaddr_t;
 struct acr_sockaddr_t {
@@ -66,6 +67,8 @@ extern "C" {
 #endif
 
 void    AcrSelectionKeyReset(JNI_STDARGS);
+int     AcrGetLocalAddr(acr_fd_t *sockfd, acr_sockaddr_t *sockaddr);
+int     AcrGetRemoteAddr(acr_fd_t *sockfd, acr_sockaddr_t *sockaddr);
 
 #ifdef __cplusplus
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c?rev=1135690&r1=1135689&r2=1135690&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c Tue Jun 14 16:43:18 2011
@@ -24,35 +24,46 @@
 #include <poll.h>
 #include <sys/un.h>
 
-ACR_NET_EXPORT(jint, SocketDescriptor, close0)(JNI_STDARGS, jint fd)
+ACR_NET_EXPORT(jint, SocketDescriptor, close0)(JNI_STDARGS, jlong fp)
 {
-    if (r_close(fd) == -1)
+    acr_fd_t *fd  = J2P(fp, acr_fd_t *);
+
+    if (fd == 0)
+        return ACR_EBADF;
+    if (r_close(fd->u.s) == -1)
         return ACR_GET_OS_ERROR();
-    else
+    else {
+        AcrFree(fd);
         return 0;
+    }
 }
 
-ACR_NET_EXPORT(jint, SocketDescriptor, sendz0)(JNI_STDARGS, jint fd)
+ACR_NET_EXPORT(jint, SocketDescriptor, sendz0)(JNI_STDARGS, jlong fp)
 {
     char dummy = 0;
-    if (r_write(fd, &dummy, 0) == -1)
+    acr_fd_t *fd  = J2P(fp, acr_fd_t *);
+
+    if (r_write(fd->u.s, &dummy, 0) == -1)
         return ACR_GET_OS_ERROR();
     else
         return 0;
 }
 
-ACR_NET_EXPORT(jint, SocketDescriptor, block0)(JNI_STDARGS, jint fd, jboolean on)
+ACR_NET_EXPORT(jint, SocketDescriptor, block0)(JNI_STDARGS, jlong fp, jboolean on)
 {
-    return AcrNonblock(fd, on == JNI_FALSE);
+    acr_fd_t *fd  = J2P(fp, acr_fd_t *);
+    return AcrNonblock(fd->u.s, on == JNI_FALSE);
 }
 
-ACR_NET_EXPORT(jboolean, SocketDescriptor, isBlocking0)(JNI_STDARGS, jint fd)
+ACR_NET_EXPORT(jboolean, SocketDescriptor, isBlocking0)(JNI_STDARGS, jlong fp)
 {
 #ifdef O_NONBLOCK
     /* Use non-blocking I/O
     */
     long mode;
-    if ((mode = fcntl(fd, F_GETFL, 0)) == -1) {
+    acr_fd_t *fd  = J2P(fp, acr_fd_t *);
+
+    if ((mode = fcntl(fd->u.s, F_GETFL, 0)) == -1) {
         ACR_THROW_NET_ERRNO();
         return JNI_TRUE;
     }

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c?rev=1135690&r1=1135689&r2=1135690&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c Tue Jun 14 16:43:18 2011
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "acr/clazz.h"
+#include "acr/netapi.h"
 #include "acr/memory.h"
 #include "acr/jniapi.h"
 #include "acr/port.h"
@@ -65,7 +65,7 @@ static short reventt(short event)
     return rv;
 }
 
-ACR_NET_EXPORT(jint, Poll, wait0)(JNI_STDARGS, jintArray fdset,
+ACR_NET_EXPORT(jint, Poll, wait0)(JNI_STDARGS, jlongArray fdset,
                                   jshortArray events, jshortArray revents,
                                   jint nevents, jint timeout)
 {
@@ -73,7 +73,7 @@ ACR_NET_EXPORT(jint, Poll, wait0)(JNI_ST
     struct pollfd pfds[1024];
     struct pollfd *pfd;
     jshort *pevents;
-    jint   *pfdset;
+    jlong  *pfdset;
     acr_time_t tmx = 0;
 
     if (nevents > 1024) {
@@ -83,10 +83,10 @@ ACR_NET_EXPORT(jint, Poll, wait0)(JNI_ST
     }
     else
         pfd = pfds;
-    pfdset  = JARRAY_CRITICAL(jint,   fdset);
+    pfdset  = JARRAY_CRITICAL(jlong,  fdset);
     pevents = JARRAY_CRITICAL(jshort, events);
     for (i = 0; i < nevents; i++) {
-        pfd[i].fd      = pfdset[i];
+        pfd[i].fd      = (J2P(pfdset[i], acr_fd_t *))->u.s;
         pfd[i].events  = ieventt(pevents[i]);
         pfd[i].revents = 0;
     }
@@ -127,14 +127,15 @@ finally:
     return ns;
 }
 
-ACR_NET_EXPORT(jshort, Poll, wait1)(JNI_STDARGS, jint fd,
+ACR_NET_EXPORT(jshort, Poll, wait1)(JNI_STDARGS, jlong fp,
                                     jshort events, jint timeout)
 {
     int ns;
     struct pollfd pfd;
     acr_time_t tmx = 0;
+    acr_fd_t *fd   = J2P(fp, acr_fd_t *);
 
-    pfd.fd      = fd;
+    pfd.fd      = fd->u.s;
     pfd.events  = ieventt(events);
     pfd.revents = 0;
 

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/selector.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/selector.c?rev=1135690&r1=1135689&r2=1135690&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/selector.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/selector.c Tue Jun 14 16:43:18 2011
@@ -440,10 +440,11 @@ ACR_NET_EXPORT(jint, PosixSelector, wait
 }
 
 ACR_NET_EXPORT(jint, PosixSelector, add0)(JNI_STDARGS, jlong pollset, jobject fo,
-                                          jint f, jint events, jint ttlms)
+                                          jlong fp, jint events, jint ttlms)
 {
     int i, rc = 0;
     acr_pollset_t *ps = J2P(pollset, acr_pollset_t *);
+    acr_fd_t *fd      = J2P(fp, acr_fd_t *);
 
     pthread_mutex_lock(&ps->mutex);
     while (ps->state != 0) {
@@ -466,14 +467,14 @@ ACR_NET_EXPORT(jint, PosixSelector, add0
         goto cleanup;
     }
     for (i = 1; i < ps->used; i++) {
-        if (ps->fdset[i].fd == f) {
+        if (ps->fdset[i].fd == fd->u.s) {
             /* Duplicate descriptor
              */
             rc = ACR_EALREADY;
             goto cleanup;
         }
     }
-    ps->fdset[ps->used].fd      = f;
+    ps->fdset[ps->used].fd      = fd->u.s;
     ps->fdset[ps->used].events  = ieventt(events);
     ps->fdset[ps->used].revents = 0;
     ps->ooset[ps->used].obj     = (*env)->NewGlobalRef(env, fo);
@@ -499,7 +500,7 @@ cleanup:
 }
 
 ACR_NET_EXPORT(jint, PosixSelector, del0)(JNI_STDARGS, jlong pollset,
-                                          jobject fo, jint f)
+                                          jobject fo, jlong fp)
 {
     int i, rc = ACR_EOF;
     acr_pollset_t *ps = J2P(pollset, acr_pollset_t *);

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c?rev=1135690&r1=1135689&r2=1135690&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c Tue Jun 14 16:43:18 2011
@@ -33,29 +33,38 @@
 #define SOCKADDR_RELEASE(BA, SA) \
     AcrReleaseArrayCritical(env, (BA), (SA))
 
-ACR_NET_EXPORT(jint, LocalDescriptor, close0)(JNI_STDARGS, jint fd)
+ACR_NET_EXPORT(jint, LocalDescriptor, close0)(JNI_STDARGS, jlong fp)
 {
-    if (r_close(fd) == -1)
+    acr_fd_t *fd = J2P(fp, acr_fd_t *);
+
+    if (fd == 0)
+        return ACR_EBADF;
+    if (r_close(fd->u.s) == -1)
         return ACR_GET_OS_ERROR();
-    else
+    else {
+        AcrFree(fd);
         return 0;
+    }
 }
 
-ACR_NET_EXPORT(jint, LocalDescriptor, sendz0)(JNI_STDARGS, jint fd)
+ACR_NET_EXPORT(jint, LocalDescriptor, sendz0)(JNI_STDARGS, jlong fp)
 {
     char dummy = 0;
-    if (r_write(fd, &dummy, 0) == -1)
+    acr_fd_t *fd = J2P(fp, acr_fd_t *);
+
+    if (r_write(fd->u.s, &dummy, 0) == -1)
         return ACR_GET_OS_ERROR();
     else
         return 0;
 }
 
-ACR_NET_EXPORT(jint, LocalDescriptor, socket0)(JNI_STDARGS, jint stype,
-                                               jboolean block)
+ACR_NET_EXPORT(jlong, LocalDescriptor, socket0)(JNI_STDARGS, jint stype,
+                                                jboolean block)
 {
     int sd;
     int rc   = 0;
     int type = 0;
+    acr_fd_t *sp;
 
     switch (stype) {
         case 1:
@@ -81,38 +90,43 @@ ACR_NET_EXPORT(jint, LocalDescriptor, so
         rc = errno;
 #if !HAVE_SOCK_CLOEXEC
     rc = AcrCloseOnExec(sd, 1);
-    if (rc != 0) {
+    if (rc != 0)
         r_close(sd);
-        sd = -1;
-    }
 #endif
 #if !HAVE_SOCK_NONBLOCK
     if (block == JNI_FALSE && rc == 0) {
         rc = AcrNonblock(sd, 1);
-        if (rc != 0) {
+        if (rc != 0)
             r_close(sd);
-            sd = -1;
-        }
     }
 #endif
     if (rc != 0) {
         ACR_THROW_NET_ERROR(rc);
+        return 0;
     }
-    return sd;
+    if ((sp = ACR_TALLOC(acr_fd_t)) == 0) {
+        r_close(sd);
+        return 0;
+    }
+    sp->u.s = sd;
+    return P2J(sp);
 }
 
-ACR_NET_EXPORT(jint, LocalDescriptor, block0)(JNI_STDARGS, jint fd, jboolean on)
+ACR_NET_EXPORT(jint, LocalDescriptor, block0)(JNI_STDARGS, jlong fp, jboolean on)
 {
-    return AcrNonblock(fd, on == JNI_FALSE);
+    acr_fd_t *fd = J2P(fp, acr_fd_t *);
+    return AcrNonblock(fd->u.s, on == JNI_FALSE);
 }
 
-ACR_NET_EXPORT(jboolean, LocalDescriptor, isBlocking0)(JNI_STDARGS, jint fd)
+ACR_NET_EXPORT(jboolean, LocalDescriptor, isBlocking0)(JNI_STDARGS, jlong fp)
 {
 #ifdef O_NONBLOCK
     /* Use non-blocking I/O
     */
     long mode;
-    if ((mode = fcntl(fd, F_GETFL, 0)) == -1) {
+    acr_fd_t *fd = J2P(fp, acr_fd_t *);
+
+    if ((mode = fcntl(fd->u.s, F_GETFL, 0)) == -1) {
         ACR_THROW_NET_ERRNO();
         return JNI_TRUE;
     }
@@ -126,15 +140,16 @@ ACR_NET_EXPORT(jboolean, LocalDescriptor
     return JNI_TRUE;
 }
 
-ACR_NET_EXPORT(jint, LocalEndpoint, connect0)(JNI_STDARGS, jint fd,
+ACR_NET_EXPORT(jint, LocalEndpoint, connect0)(JNI_STDARGS, jlong fp,
                                               jbyteArray cb, jint timeout)
 {
     int rc;
     acr_sockaddr_t *ca = SOCKADDR_CAST(cb);
+    acr_fd_t *fd       = J2P(fp, acr_fd_t *);
 
     do {
         /* Restartable connect */
-        rc = connect(fd, (const struct sockaddr *)&ca->sa.sin, ca->salen);
+        rc = connect(fd->u.s, (const struct sockaddr *)&ca->sa.sin, ca->salen);
     } while (rc == -1 && errno == EINTR);
 
     if (rc == -1)
@@ -142,12 +157,12 @@ ACR_NET_EXPORT(jint, LocalEndpoint, conn
     SOCKADDR_RELEASE(cb, ca);
     if (rc != 0) {
         if (timeout > 0 && (rc == EINPROGRESS || rc == EALREADY)) {
-            rc = AcrWaitIO(fd, timeout, POLLOUT);
+            rc = AcrWaitIO(fd->u.s, timeout, POLLOUT);
 #if defined(SO_ERROR)
             if (rc == 0) {
                 int       err;
                 socklen_t len = sizeof(err);
-                if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (char *)&err, &len) == -1);
+                if (getsockopt(fd->u.s, SOL_SOCKET, SO_ERROR, (char *)&err, &len)
== -1);
                     rc = errno;
                 if (err != 0)
                     rc = err;
@@ -158,17 +173,18 @@ ACR_NET_EXPORT(jint, LocalEndpoint, conn
     return rc;
 }
 
-ACR_NET_EXPORT(jint, LocalServerEndpoint, bind0)(JNI_STDARGS, jint fd,
+ACR_NET_EXPORT(jint, LocalServerEndpoint, bind0)(JNI_STDARGS, jlong fp,
                                                  jbyteArray ba,
                                                  jint backlog)
 {
     int rc = 0;
     acr_sockaddr_t *aa = SOCKADDR_CAST(ba);
+    acr_fd_t *fd       = J2P(fp, acr_fd_t *);
 
-    if (bind(fd, (const struct sockaddr *)&aa->sa, aa->salen) == -1)
+    if (bind(fd->u.s, (const struct sockaddr *)&aa->sa, aa->salen) == -1)
         rc = errno;
     SOCKADDR_RELEASE(ba, aa);
-    if (rc == 0 && listen(fd, backlog) == -1)
+    if (rc == 0 && listen(fd->u.s, backlog) == -1)
         rc = errno;
     return rc;
 }
@@ -184,13 +200,15 @@ ACR_NET_EXPORT(void, LocalServerEndpoint
     SOCKADDR_RELEASE(ba, sa);
 }
 
-ACR_NET_EXPORT(jint, LocalServerEndpoint, accept0)(JNI_STDARGS, jint fd,
-                                                   jbyteArray ba,
-                                                   jboolean block)
+ACR_NET_EXPORT(jlong, LocalServerEndpoint, accept0)(JNI_STDARGS, jlong fp,
+                                                    jbyteArray ba,
+                                                    jboolean block)
 {
     int sd;
     acr_sockaddr_t  aa;
     socklen_t       aalen;
+    acr_fd_t *fd  = J2P(fp, acr_fd_t *);
+    acr_fd_t *sp;
 #if HAVE_ACCEPT4
     int flags = SOCK_CLOEXEC;
 #endif
@@ -203,15 +221,15 @@ ACR_NET_EXPORT(jint, LocalServerEndpoint
     aalen = ISIZEOF(struct sockaddr_un);
     do {
 #if HAVE_ACCEPT4
-        sd = accept4(fd, (struct sockaddr *)&aa.sa, &aalen, flags);
+        sd = accept4(fd->u.s, (struct sockaddr *)&aa.sa, &aalen, flags);
 #else
-        sd = accept(fd,  (struct sockaddr *)&aa.sa, &aalen);
+        sd = accept(fd->u.s,  (struct sockaddr *)&aa.sa, &aalen);
 #endif
     } while (sd == -1 && errno == EINTR);
 
     if (sd == -1) {
         ACR_THROW_NET_ERRNO();
-        return -1;
+        return 0;
     }
 #if !HAVE_ACCEPT4
     {
@@ -219,7 +237,7 @@ ACR_NET_EXPORT(jint, LocalServerEndpoint
         if (rc != 0) {
             r_close(sd);
             ACR_THROW_NET_ERROR(rc);
-            return -1;
+            return 0;
         }
     }
 #endif
@@ -229,7 +247,7 @@ ACR_NET_EXPORT(jint, LocalServerEndpoint
         if (rc != 0) {
             r_close(sd);
             ACR_THROW_NET_ERROR(rc);
-            return -1;
+            return 0;
         }
     }
 #endif
@@ -239,5 +257,10 @@ ACR_NET_EXPORT(jint, LocalServerEndpoint
         fflush(stderr);
     }
 #endif
-    return sd;
+    if ((sp = ACR_TALLOC(acr_fd_t)) == 0) {
+        r_close(sd);
+        return 0;
+    }
+    sp->u.s = sd;
+    return P2J(sp);
 }

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=1135690&r1=1135689&r2=1135690&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c Tue Jun 14 16:43:18
2011
@@ -37,50 +37,39 @@ J_DECLARE_F_ID(0000) = {
     INVALID_FIELD_OFFSET,
     0,
     "fd",
-    "I"
+    "J"
 };
 
-J_DECLARE_F_ID(0001) = {
-    INVALID_FIELD_OFFSET,
-    INVALID_FIELD_OFFSET,
-    0,
-    "ad",
-    "Ljava/lang/Object;"
-};
-
-
 ACR_IO_EXPORT(void, Descriptor, init0)(JNI_STDARGS)
 {
     _clazzn.i = (jclass)(*env)->NewGlobalRef(env, obj);
     if (_clazzn.i == 0)
         return;
     V_LOAD_IFIELD(0000);
-    V_LOAD_IFIELD(0001);
     UNSAFE_IFIELD(0000);
-    UNSAFE_IFIELD(0001);
     _clazzn.u = 1;
 }
 
-int
-AcrGetDescriptorFd(JNI_STDARGS)
+acr_fd_t *
+AcrGetDescriptorFp(JNI_STDARGS)
 {
-    int fd = -1;
+    jlong fp = 0;
 
     if (J4FLD_OFF(0000) != INVALID_FIELD_OFFSET) {
         char *oa = *(char **)obj;
         if (oa != 0) {
             char *fa = (oa + J4FLD_PTR(0000));
-            fd = *((int *)fa);
+            fp = *((jlong *)fa);
         }
     }
     else if (CLAZZ_LOADED) {
-        fd = GET_IFIELD_I(0000, obj);
+        fp = GET_IFIELD_J(0000, obj);
     }
-    return fd;
+    return J2P(fp, acr_fd_t *);
 }
 
 int
-AcrSetDescriptorFd(JNI_STDARGS, int fd)
+AcrSetDescriptorFp(JNI_STDARGS, acr_fd_t *fd)
 {
     int rc = ACR_EBADF;
 
@@ -88,50 +77,12 @@ AcrSetDescriptorFd(JNI_STDARGS, int fd)
         char *oa = *(char **)obj;
         if (oa != 0) {
             char *fa = (oa + J4FLD_PTR(0000));
-            *((int *)fa) = fd;
-            rc = 0;
-        }
-    }
-    else if (CLAZZ_LOADED) {
-        SET_IFIELD_I(0000, obj, fd);
-        rc = 0;
-    }
-    return rc;
-}
-
-jobject
-AcrGetDescriptorCtx(JNI_STDARGS)
-{
-    jobject ob = 0;
-
-    if (J4FLD_OFF(0001) != INVALID_FIELD_OFFSET) {
-        char *oa = *(char **)obj;
-        if (oa != 0) {
-            char *fa = (oa + J4FLD_PTR(0001));
-            ob = *((jobject *)fa);
-        }
-    }
-    else if (CLAZZ_LOADED) {
-        ob = GET_IFIELD_O(0001, obj);
-    }
-    return ob;
-}
-
-int
-AcrSetDescriptorCtx(JNI_STDARGS, jobject ob)
-{
-    int   rc = ACR_EBADF;
-
-    if (J4FLD_OFF(0001) != INVALID_FIELD_OFFSET) {
-        char *oa = *(char **)obj;
-        if (oa != 0) {
-            char *fa = (oa + J4FLD_PTR(0001));
-            *((jobject *)fa) = ob;
+            *((jlong *)fa) = P2J(fd);
             rc = 0;
         }
     }
     else if (CLAZZ_LOADED) {
-        SET_IFIELD_O(0001, obj, ob);
+        SET_IFIELD_P(0000, obj, fd);
         rc = 0;
     }
     return rc;

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c?rev=1135690&r1=1135689&r2=1135690&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c Tue Jun 14 16:43:18 2011
@@ -409,10 +409,10 @@ sockaddr_to_ipstr(char *buf, int buflen,
 }
 
 int
-AcrGetLocalAddr(int sockfd, acr_sockaddr_t *sockaddr)
+AcrGetLocalAddr(acr_fd_t *sockfd, acr_sockaddr_t *sockaddr)
 {
     socklen_t salen = sizeof(sockaddr->sa);
-    if (getsockname(ACR_SOCKET(sockfd), (struct sockaddr *)&sockaddr->sa, &salen)
== SOCKET_ERROR) {
+    if (getsockname(sockfd->u.s, (struct sockaddr *)&sockaddr->sa, &salen)
== SOCKET_ERROR) {
         return ACR_GET_NETOS_ERROR();
     }
     else {
@@ -423,10 +423,10 @@ AcrGetLocalAddr(int sockfd, acr_sockaddr
 }
 
 int
-AcrGetRemoteAddr(int sockfd, acr_sockaddr_t *sockaddr)
+AcrGetRemoteAddr(acr_fd_t *sockfd, acr_sockaddr_t *sockaddr)
 {
     socklen_t salen = sizeof(sockaddr->sa);
-    if (getpeername(ACR_SOCKET(sockfd), (struct sockaddr *)&sockaddr->sa, &salen)
== SOCKET_ERROR) {
+    if (getpeername(sockfd->u.s, (struct sockaddr *)&sockaddr->sa, &salen)
== SOCKET_ERROR) {
         return ACR_GET_NETOS_ERROR();
     }
     else {



Mime
View raw message