commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1133664 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/net/LocalDescriptor.java native/configure native/os/unix/usock.c native/os/win32/config.hw
Date Thu, 09 Jun 2011 05:54:19 GMT
Author: mturk
Date: Thu Jun  9 05:54:18 2011
New Revision: 1133664

URL: http://svn.apache.org/viewvc?rev=1133664&view=rev
Log:
Add method for creating non blocking sockets directly.

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalDescriptor.java
    commons/sandbox/runtime/trunk/src/main/native/configure
    commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/config.hw

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=1133664&r1=1133663&r2=1133664&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
Thu Jun  9 05:54:18 2011
@@ -38,7 +38,7 @@ final class LocalDescriptor extends Desc
 {
     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     socket0(int type, boolean blocking)
         throws IOException;
     private static native int     block0(int fd, boolean block);
     private static native boolean isBlocking0(int fd)
@@ -58,7 +58,13 @@ final class LocalDescriptor extends Desc
     public void create(SocketType type)
         throws IOException
     {
-        this.fd = socket0(type.valueOf());
+        create(type, true);
+    }
+
+    public void create(SocketType type, boolean block)
+        throws IOException
+    {
+        this.fd = socket0(type.valueOf(), block);
     }
 
     public boolean isBlocking()

Modified: commons/sandbox/runtime/trunk/src/main/native/configure
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/configure?rev=1133664&r1=1133663&r2=1133664&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/configure (original)
+++ commons/sandbox/runtime/trunk/src/main/native/configure Thu Jun  9 05:54:18 2011
@@ -1379,6 +1379,7 @@ extern "C" {
 #define HAVE_GETSERVBYNAME_R    `have_function x getservbyname_r`
 #define HAVE_GETIFADDRS         `have_function x getifaddrs`
 #define HAVE_SOCK_CLOEXEC       `have_socket AF_INET 'SOCK_STREAM|SOCK_CLOEXEC' SOCK_CLOEXEC`
+#define HAVE_SOCK_NONBLOCK      `have_socket AF_INET 'SOCK_STREAM|SOCK_NONBLOCK' SOCK_NONBLOCK`
 #define HAVE_FILE_CLOEXEC       `have_defined O_CLOEXEC`
 #define HAVE_SO_ACCEPTFILTER    `have_defined SO_ACCEPTFILTER`
 #define HAVE_TM_TM_GMTOFF       `have_strcut_member time 'struct tm' tm_gmtoff`

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=1133664&r1=1133663&r2=1133664&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 Thu Jun  9 05:54:18 2011
@@ -50,7 +50,8 @@ ACR_NET_EXPORT(jint, LocalDescriptor, se
         return 0;
 }
 
-ACR_NET_EXPORT(jint, LocalDescriptor, socket0)(JNI_STDARGS, jint stype)
+ACR_NET_EXPORT(jint, LocalDescriptor, socket0)(JNI_STDARGS, jint stype,
+                                               jboolean block)
 {
     int sd;
     int rc   = 0;
@@ -68,16 +69,26 @@ ACR_NET_EXPORT(jint, LocalDescriptor, so
         break;
 
     }
-#if !HAVE_SOCK_CLOEXEC
-    sd = socket(AF_LOCAL, type, 0);
-#else
-    sd = socket(AF_LOCAL, type | SOCK_CLOEXEC, 0);
+#if HAVE_SOCK_NONBLOCK
+    if (block == JNI_FALSE)
+        type |= SOCK_NONBLOCK;
+#endif
+#if HAVE_SOCK_CLOEXEC
+    type |= SOCK_CLOEXEC;
 #endif
+    sd = socket(AF_LOCAL, type, 0);
     if (sd == -1)
         rc = errno;
 #if !HAVE_SOCK_CLOEXEC
-    else {
-        rc = AcrCloseOnExec(sd, 1);
+    rc = AcrCloseOnExec(sd, 1);
+    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) {
             r_close(sd);
             sd = -1;

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/config.hw
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/config.hw?rev=1133664&r1=1133663&r2=1133664&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/config.hw (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/config.hw Thu Jun  9 05:54:18 2011
@@ -117,6 +117,7 @@
 #define HAVE_GETSERVBYNAME_R    0
 #define HAVE_GETIFADDRS         0
 #define HAVE_SOCK_CLOEXEC       0
+#define HAVE_SOCK_NONBLOCK      0
 #define HAVE_FILE_CLOEXEC       0
 #define HAVE_SO_ACCEPTFILTER    0
 #define HAVE_TM_TM_GMTOFF       0



Mime
View raw message