commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1130917 - in /commons/sandbox/runtime/trunk/src/main/native/os/unix: inetsock.c usock.c
Date Fri, 03 Jun 2011 07:17:03 GMT
Author: mturk
Date: Fri Jun  3 07:17:03 2011
New Revision: 1130917

URL: http://svn.apache.org/viewvc?rev=1130917&view=rev
Log:
Add connect0 timeout

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c

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=1130917&r1=1130916&r2=1130917&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 Fri Jun  3 07:17:03 2011
@@ -34,7 +34,8 @@ ACR_NET_EXPORT(jint, SocketDescriptor, c
 
 ACR_NET_EXPORT(jint, SocketDescriptor, sendz0)(JNI_STDARGS, jint fd)
 {
-    if (r_write(fd, &fd, 0) == -1)
+    char dummy = 0;
+    if (r_write(fd, &dummy, 0) == -1)
         return ACR_GET_OS_ERROR();
     else
         return 0;

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=1130917&r1=1130916&r2=1130917&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 Fri Jun  3 07:17:03 2011
@@ -43,7 +43,8 @@ ACR_NET_EXPORT(jint, LocalDescriptor, cl
 
 ACR_NET_EXPORT(jint, LocalDescriptor, sendz0)(JNI_STDARGS, jint fd)
 {
-    if (r_write(fd, &fd, 0) == -1)
+    char dummy = 0;
+    if (r_write(fd, &dummy, 0) == -1)
         return ACR_GET_OS_ERROR();
     else
         return 0;
@@ -55,57 +56,69 @@ ACR_NET_EXPORT(jint, LocalEndpoint, nonb
 }
 
 ACR_NET_EXPORT(jint, LocalEndpoint, connect0)(JNI_STDARGS, jint fd,
-                                              jbyteArray aa)
+                                              jbyteArray cb, jint timeout)
 {
-    int sd;
-    acr_sockaddr_t *sa = SOCKADDR_CAST(aa);
+    int rc;
+    acr_sockaddr_t *ca = SOCKADDR_CAST(cb);
 
     do {
         /* Restartable connect */
-        sd = connect(fd, (const struct sockaddr *)&sa->sa, sa->salen);
-    } while (sd == -1 && errno == EINTR);
+        rc = connect(fd, (const struct sockaddr *)&ca->sa.sin, ca->salen);
+    } while (rc == -1 && errno == EINTR);
 
-    if (sd == -1) {
-        ACR_THROW_NET_ERRNO();
-        return -1;
+    if (rc == -1) {
+        rc = errno;
+        if (timeout > 0 && (errno == EINPROGRESS || errno == EALREADY)) {
+            rc = AcrWaitIO(fd, 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);
+                    rc = errno;
+                if (err != 0)
+                    rc = err;
+            }
+#endif
+        }
     }
-    SOCKADDR_RELEASE(aa, sa);
-    return sd;
+    SOCKADDR_RELEASE(cb, ca);
+    return rc;
 }
 
 ACR_NET_EXPORT(jint, LocalServerEndpoint, bind0)(JNI_STDARGS, jint fd,
-                                                 jbyteArray aa,
+                                                 jbyteArray ba,
                                                  jint backlog)
 {
     int rc = 0;
-    acr_sockaddr_t *sa = SOCKADDR_CAST(aa);
+    acr_sockaddr_t *aa = SOCKADDR_CAST(ba);
 
-    if (bind(fd, (const struct sockaddr *)&sa->sa, sa->salen) == -1) {
+    if (bind(fd, (const struct sockaddr *)&aa->sa, aa->salen) == -1) {
         rc = ACR_GET_NETOS_ERROR();
-        SOCKADDR_RELEASE(aa, sa);
+        SOCKADDR_RELEASE(ba, aa);
         return rc;
     }
     if (listen(fd, backlog) == -1)
         rc = ACR_GET_NETOS_ERROR();
-    SOCKADDR_RELEASE(aa, sa);
+    SOCKADDR_RELEASE(ba, aa);
     return rc;
 }
 
 ACR_NET_EXPORT(jint, LocalServerEndpoint, accept0)(JNI_STDARGS, jint fd,
-                                                   jbyteArray aa)
+                                                   jbyteArray ba)
 {
     int sd;
-    acr_sockaddr_t sa;
-    socklen_t      salen;
+    acr_sockaddr_t  aa;
+    socklen_t       aalen;
 
-    memset(&sa, 0, sizeof(sa));
-    salen = ISIZEOF(struct sockaddr_un);
+    memset(&aa, 0, sizeof(aa));
+    aalen = ISIZEOF(struct sockaddr_un);
 
     do {
 #if !HAVE_ACCEPT4
-        sd = accept(fd,  (struct sockaddr *)&sa.sa, &salen);
+        sd = accept(fd,  (struct sockaddr *)&aa.sa, &aalen);
 #else
-        sd = accept4(fd, (struct sockaddr *)&sa.sa, &salen, SOCK_CLOEXEC);
+        sd = accept4(fd, (struct sockaddr *)&aa.sa, &aalen, SOCK_CLOEXEC);
 #endif
     } while (sd == -1 && errno == EINTR);
 
@@ -117,20 +130,20 @@ ACR_NET_EXPORT(jint, LocalServerEndpoint
     AcrCloseOnExec(sd, 1);
 #endif
 #if defined(DEBUG) || defined(_DEBUG)
-    if (sa.sa.unx.sun_family != AF_LOCAL) {
-        fprintf(stderr, "Expected AF_LOCAL but found %d\n", sa.sa.unx.sun_family);
+    if (aa.sa.unx.sun_family != AF_LOCAL) {
+        fprintf(stderr, "Expected AF_LOCAL but found %d\n", aa.sa.unx.sun_family);
         fflush(stderr);
     }
 #endif    
-    sa.family  = AF_LOCAL;
-    sa.salen   = ISIZEOF(struct sockaddr_un);
-    sa.addrlen = ISIZEOF(sa.sa.unx.sun_path);
-    sa.iplen   = sa.addrlen;
-    sa.addrcnt = 1;
+    aa.family  = AF_LOCAL;
+    aa.salen   = ISIZEOF(struct sockaddr_un);
+    aa.addrlen = ISIZEOF(aa.sa.unx.sun_path);
+    aa.iplen   = aa.addrlen;
+    aa.addrcnt = 1;
     /* Copy sockaddr to the provided byte array
      * Note that byte array must be of valid size
      */
-    (*env)->SetByteArrayRegion(env, aa, 0, ISIZEOF(acr_sockaddr_t), (jbyte *)&sa);
+    (*env)->SetByteArrayRegion(env, ba, 0, ISIZEOF(acr_sockaddr_t), (jbyte *)&aa);
 
     return sd;
 }



Mime
View raw message