Author: mturk
Date: Wed Jul 13 10:26:07 2011
New Revision: 1145948

URL: http://svn.apache.org/viewvc?rev=1145948&view=rev
Log:
Set socket to blocking if requested and acceptor was nonblocking

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/unix/localsock.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/localsock.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/localsock.c?rev=1145948&r1=1145947&r2=1145948&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/localsock.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/localsock.c Wed Jul 
13 10:26:07 2011
@@ -377,6 +377,19 @@ ACR_NET_EXPORT(jlong, LocalServerEndpoin
             return 0;
         }
     }
+#if HAVE_NONBLOCK_INHERITED
+    else if ((fd->flags & ACR_DT_NONBLOCK) != 0) {
+        /* We have nonblocking acceptor and need
+         * blocking socket
+         */
+        rc = AcrNonblock(sd, 0);
+        if (rc != 0) {
+            r_close(sd);
+            ACR_THROW_NET_ERROR(rc);
+            return 0;
+        }
+    }
+#endif
 #if defined(DEBUG) || defined(_DEBUG)
     if (aa.sa.unx.sun_family != AF_LOCAL) {
         fprintf(stderr, "Expected AF_LOCAL but found %d\n", 
aa.sa.unx.sun_family);
@@ -388,7 +401,7 @@ ACR_NET_EXPORT(jlong, LocalServerEndpoin
         return 0;
     }
     sp->type    = ACR_DT_LSOCK;
-    sp->flags   = fd->flags;
+    sp->flags   = fd->flags & ~ACR_DT_NONBLOCK;
     sp->timeout = fd->timeout;
     sp->refs    = 1;
     sp->u.s     = sd;

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c?rev=1145948&r1=1145947&r2=1145948&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c 
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c Wed Jul 
13 10:26:07 2011
@@ -391,16 +391,24 @@ ACR_NET_EXPORT(jlong, LocalServerEndpoin
         ACR_THROW_NET_ERRNO();
         return 0;
     }
-    if (block == JNI_FALSE && (wd->fd.flags & ACR_DT_NONBLOCK) == 0) {
-        int rc = AcrNonblock(sd, 1);
+    if (block == JNI_FALSE) {
+        if ((wd->fd.flags & ACR_DT_NONBLOCK) == 0) {
+            int rc = AcrNonblock(sd, 1);
+            if (rc != 0) {
+                closesocket(sd);
+                ACR_THROW_NET_ERROR(rc);
+                return 0;
+            }
+        }
+    }
+    else if ((wd->fd.flags & ACR_DT_NONBLOCK) != 0) {
+        int rc = AcrNonblock(sd, 0);
         if (rc != 0) {
             closesocket(sd);
             ACR_THROW_NET_ERROR(rc);
             return 0;
         }
     }
-    else
-        block = JNI_TRUE;
     if ((sp = ACR_TALLOC(wls_fd_t)) == 0) {
         closesocket(sd);
         return 0;
@@ -414,7 +422,7 @@ ACR_NET_EXPORT(jlong, LocalServerEndpoin
     SOCKADDR_RELEASE(ba, aa);
     
     sp->fd.type    = ACR_DT_LSOCK;
-    sp->fd.flags   = wd->fd.flags;
+    sp->fd.flags   = wd->fd.flags & ~ACR_DT_NONBLOCK;
     sp->fd.timeout = wd->fd.timeout;
     sp->fd.refs    = 1;
     sp->fd.u.s     = sd;


Reply via email to