commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1142889 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/net/ native/os/unix/ native/shared/
Date Tue, 05 Jul 2011 04:20:37 GMT
Author: mturk
Date: Tue Jul  5 04:20:36 2011
New Revision: 1142889

URL: http://svn.apache.org/viewvc?rev=1142889&view=rev
Log:
Implement posix inet socket

Modified:
    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/SocketDescriptor.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
    commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c
    commons/sandbox/runtime/trunk/src/main/native/shared/array.c

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=1142889&r1=1142888&r2=1142889&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 Jul  5 04:20:36 2011
@@ -60,10 +60,10 @@ final class LocalDescriptor extends Desc
         create(type, true);
     }
 
-    public void create(SocketType type, boolean block)
+    public void create(SocketType type, boolean blocking)
         throws IOException
     {
-        this.fd = socket0(type.valueOf(), block);
+        this.fd = socket0(type.valueOf(), blocking);
         closed  = false;
     }
 

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=1142889&r1=1142888&r2=1142889&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 Jul  5 04:20:36 2011
@@ -91,6 +91,7 @@ public class LocalEndpoint extends Endpo
                 throw new IOException(Status.describe(rc));
         }
         ea = endpoint;
+        connected = true;
     }
 
     public final void connect(EndpointAddress endpoint)

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=1142889&r1=1142888&r2=1142889&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 Jul  5 04:20:36 2011
@@ -166,7 +166,7 @@ public class LocalServerEndpoint extends
             throw new IOException(Local.sm.get("endpoint.EBOUND"));
         if (sd.closed())
             sd.create(SocketType.STREAM, blocking);
-        if (backlog < LISTEN_BACKLOG)
+        if (backlog == 0)
             backlog = LISTEN_BACKLOG;
         int rc = bind0(sd.fd(), endpoint.sockaddr(), backlog);
         if (rc != 0) {

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=1142889&r1=1142888&r2=1142889&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 Jul  5 04:20:36 2011
@@ -35,7 +35,7 @@ final class SocketDescriptor extends Des
 
     private static native int     close0(long fd);
     private static native int     sendz0(long fd);
-    private static native long    socket0(int type)
+    private static native long    socket0(int af, int type, boolean blocking)
         throws IOException;
     private static native int     block0(long fd, boolean block);
     private static native boolean isBlocking0(long fd)
@@ -51,10 +51,16 @@ final class SocketDescriptor extends Des
         closed  = false;
     }
 
-    public void create(SocketType type)
+    public void create(AddressFamily af, SocketType type)
         throws IOException
     {
-        this.fd = socket0(type.valueOf());
+        create(af, type, true);
+    }
+
+    public void create(AddressFamily af, SocketType type, boolean blocking)
+        throws IOException
+    {
+        this.fd = socket0(af.valueOf(), type.valueOf(), blocking);
         closed  = false;
     }
 

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java?rev=1142889&r1=1142888&r2=1142889&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
Tue Jul  5 04:20:36 2011
@@ -67,6 +67,11 @@ public class SocketEndpoint extends Endp
     {
         if (connected)
             throw new IOException(Local.sm.get("endpoint.ECONNECTED"));
+        if (sd.closed())
+            sd.create(endpoint.getFamily(), SocketType.STREAM);
+        
+        ea = endpoint;
+        connected = true;
     }
 
     public final void connect(SocketAddress endpoint)

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=1142889&r1=1142888&r2=1142889&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 Jul  5 04:20:36 2011
@@ -25,6 +25,72 @@
 #include <poll.h>
 #include <sys/un.h>
 
+ACR_NET_EXPORT(jlong, SocketDescriptor, socket0)(JNI_STDARGS, jint saf,
+                                                 jint stype, jboolean block)
+{
+    int sd;
+    int rc   = 0;
+    int af   = AF_UNSPEC;
+    int type = 0;
+    acr_fd_t *sp;
+
+    switch (stype) {
+        case 1:
+            type = SOCK_STREAM;
+        break;
+        case 2:
+            type = SOCK_DGRAM;
+        break;
+        case 3:
+            type = SOCK_RAW;
+        break;
+    }
+    switch (saf) {
+        case 1:
+            af = AF_INET;
+        break;
+        case 2:
+            af = AF_INET6;
+        break;
+        case 3:
+            af = AF_LOCAL;
+        break;
+    }
+#if HAVE_SOCK_NONBLOCK
+    if (block == JNI_FALSE)
+        type |= SOCK_NONBLOCK;
+#endif
+#if HAVE_SOCK_CLOEXEC
+    type |= SOCK_CLOEXEC;
+#endif
+    sd = socket(af, type, 0);
+    if (sd == -1)
+        rc = errno;
+#if !HAVE_SOCK_CLOEXEC
+    rc = AcrCloseOnExec(sd, 1);
+    if (rc != 0)
+        r_close(sd);
+#endif
+#if !HAVE_SOCK_NONBLOCK
+    if (block == JNI_FALSE && rc == 0) {
+        rc = AcrNonblock(sd, 1);
+        if (rc != 0)
+            r_close(sd);
+    }
+#endif
+    if (rc != 0) {
+        ACR_THROW_NET_ERROR(rc);
+        return 0;
+    }
+    if ((sp = ACR_TALLOC(acr_fd_t)) == 0) {
+        r_close(sd);
+        return 0;
+    }
+    sp->refs = 1;
+    sp->u.s  = sd;
+    return P2J(sp);
+}
+
 ACR_NET_EXPORT(jint, SocketDescriptor, close0)(JNI_STDARGS, jlong fp)
 {
     int rc = 0;

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/array.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/array.c?rev=1142889&r1=1142888&r2=1142889&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/array.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/array.c Tue Jul  5 04:20:36 2011
@@ -209,3 +209,29 @@ ACR_UTIL_EXPORT(jint, Array, memcmp0)(JN
     RELEASE_CRITICAL(dst, dcp);
     return rv;
 }
+
+ACR_UTIL_EXPORT(jbyteArray, Array, dup0)(JNI_STDARGS,
+                                         jarray src,
+                                         jint srcPos,
+                                         jint srcSiz,
+                                         jint length)
+{
+    jbyteArray ra;
+    jbyte *scp;
+    jint   srcOff = srcPos * srcSiz;
+    jsize  nbytes = length * srcSiz;
+
+    scp = JARRAY_CRITICAL(jbyte, src);
+    if (scp == 0) {
+        RELEASE_CRITICAL(src, scp);
+        return 0;
+    }
+    ra = (*env)->NewByteArray(env, nbytes);
+    if (ra == 0) {
+        RELEASE_CRITICAL(src, scp);
+        return 0;
+    }
+    (*env)->SetByteArrayRegion(env, ra, 0, nbytes, scp  + (size_t)srcOff);
+    RELEASE_CRITICAL(src, scp);
+    return ra;
+}



Mime
View raw message