commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1165622 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr/string.h os/win32/sendfd.c
Date Tue, 06 Sep 2011 12:02:20 GMT
Author: mturk
Date: Tue Sep  6 12:02:20 2011
New Revision: 1165622

URL: http://svn.apache.org/viewvc?rev=1165622&view=rev
Log:
Add string exit cleanup macro

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h
    commons/sandbox/runtime/trunk/src/main/native/os/win32/sendfd.c

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h?rev=1165622&r1=1165621&r2=1165622&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/string.h Tue Sep  6 12:02:20
2011
@@ -86,6 +86,8 @@
         if (_s##V != 0 && _s##V != _b##V) AcrFree(_s##V);                   \
     } while(0)
 
+#define BREAK_WITH_STR(V) goto _e##V
+
 /* NOTE: Usable only where sizeof(wchar_t) == sizeof(jchar)
  * So far this is only true for Windows.
  */

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/sendfd.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/sendfd.c?rev=1165622&r1=1165621&r2=1165622&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/sendfd.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/sendfd.c Tue Sep  6 12:02:20 2011
@@ -103,12 +103,13 @@ ACR_NET_EXPORT(jint, Utils, sendfd0)(JNI
         pipe = send_pipe(J2S(name), &cpid);
         if (pipe == 0) {
             rc = ACR_GET_OS_ERROR();
-            goto cleanup;
+            BREAK_WITH_STR(name);
         }
         fds = (*env)->GetLongArrayElements(env, fda, 0);
         if (fds == 0) {
             rc = ACR_EINVAL;
-            goto cleanup;
+            CloseHandle(pipe);
+            BREAK_WITH_STR(name);
         }
         for (i = 0; i < len; i++) {
             acr_sd_t *sp = J2P(fds[i + off], acr_sd_t *);
@@ -126,8 +127,7 @@ ACR_NET_EXPORT(jint, Utils, sendfd0)(JNI
             }
         }
         (*env)->ReleaseLongArrayElements(env, fda, fds, JNI_ABORT);
-cleanup:
-        SAFE_CLOSE_HANDLE(pipe);
+        CloseHandle(pipe);
     } DONE_WITH_STR(name);
     return rc;
 }
@@ -139,45 +139,43 @@ ACR_NET_EXPORT(jlongArray, Utils, recvfd
     jlong sda[MAX_SEND_FDS];
 
     WITH_WSTR(name) {
-        HANDLE pipe;
-        if ((pipe = recv_pipe(J2S(name))) == 0) {
+        int nfd;
+        HANDLE pipe = recv_pipe(J2S(name));
+        if (pipe == 0) {
             rc = ACR_GET_OS_ERROR();
+            BREAK_WITH_STR(name);
         }
-        else {
-            int nfd;
-
-            for (nfd = 0; nfd < MAX_SEND_FDS; nfd++) {
-                WSAPROTOCOL_INFO pi;
-                DWORD  rd;
-                SOCKET sd;
-                acr_sd_t *sp;
+        for (nfd = 0; nfd < MAX_SEND_FDS; nfd++) {
+            WSAPROTOCOL_INFO pi;
+            DWORD  rd;
+            SOCKET sd;
+            acr_sd_t *sp;
 
-                if (!ReadFile(pipe, &pi, sizeof(WSAPROTOCOL_INFO), &rd, 0))
-                    break;
-                sd = WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO,
&pi, 0, 0);
-                if (sd == INVALID_SOCKET) {
-                    rc = WSAGetLastError();
-                    break;
-                }
-                sp = ACR_TALLOC(acr_sd_t);
-                if (sp == 0) {
-                    rc = ACR_ENOMEM;
-                    break;
-                }
-                sp->type    = ACR_DT_SOCKET;
-                sp->refs    = 1;
-                sp->s       = sd;
-                sp->timeout = -1;
-                sda[nfd]    = P2J(sp);
+            if (!ReadFile(pipe, &pi, sizeof(WSAPROTOCOL_INFO), &rd, 0))
+                break;
+            sd = WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, &pi,
0, 0);
+            if (sd == INVALID_SOCKET) {
+                rc = WSAGetLastError();
+                break;
+            }
+            /* Make it non inheritable */
+            SetHandleInformation((HANDLE)sd, HANDLE_FLAG_INHERIT, 0);               
+            sp = ACR_TALLOC(acr_sd_t);
+            if (sp == 0) {
+                rc = ACR_ENOMEM;
+                break;
             }
-            if (rc != 0 || nfd == 0)
-                goto cleanup;
-            fds = (*env)->NewLongArray(env, nfd);
-            if (fds != 0)
+            sp->type    = ACR_DT_SOCKET;
+            sp->refs    = 1;
+            sp->s       = sd;
+            sp->timeout = -1;
+            sda[nfd]    = P2J(sp);
+        }
+        if (rc == 0 && nfd > 0) {
+            if ((fds = (*env)->NewLongArray(env, nfd)) != 0)
                 (*env)->SetLongArrayRegion(env, fds, 0, nfd, sda);
-cleanup:
-            CloseHandle(pipe);
         }
+        CloseHandle(pipe);
     } DONE_WITH_STR(name);
     if (rc != 0)
         ACR_THROW_NET_ERROR(rc);



Mime
View raw message