Author: mturk
Date: Thu Nov 26 13:19:25 2009
New Revision: 884551

URL: http://svn.apache.org/viewvc?rev=884551&view=rev
Log:
Fix pipe cleanup

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysrw.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysrw.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysrw.c?rev=884551&r1=884550&r2=884551&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysrw.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysrw.c Thu Nov 26 
13:19:25 2009
@@ -32,6 +32,60 @@
 extern int do_lock(acr_file_t *f, DWORD flags);
 extern int do_unlock(acr_file_t *f);
 
+static DWORD overlapped_wait(acr_file_t *f, DWORD *nbytes)
+{
+    DWORD ws;
+    DWORD rc = 0;
+
+    do {
+        switch (ws = ACR_WaitForObjectOrSignal(f->overlap.hEvent,
+                                               f->timeout)) {
+            case WAIT_IO_COMPLETION:
+            case WAIT_ABANDONED_0:
+            case WAIT_ABANDONED_1:
+            case WAIT_OBJECT_0:
+                /* Signal event is set.
+                 * Get it's status.
+                 */
+                rc = ACR_DeliverSignals();
+            break;
+            case WAIT_OBJECT_1:
+                /* Operation success */
+                rc = 0;
+            break;
+            case WAIT_FAILED:
+                /* We got the error while waiting
+                 */
+                rc = ACR_GET_OS_ERROR();
+            break;
+            case WAIT_TIMEOUT:
+                rc = ACR_TIMEUP;
+            break;
+            default:
+                rc = ACR_EINVAL;
+            break;
+        }
+    } while (rc == ACR_EINTR);
+
+    if (rc) {
+        /* There is one case that represents entirely
+         * successful operations, otherwise we will cancel
+         * the operation in progress.
+         */
+        CancelIo(f->fd);
+    }
+    if (!GetOverlappedResult(f->fd,
+                             &f->overlap,
+                             nbytes,
+                             FALSE)) {
+        rc = GetLastError();
+        if (rc == ERROR_IO_INCOMPLETE ||
+            rc == ERROR_OPERATION_ABORTED)
+            rc = ACR_TIMEUP;
+    }
+    return rc;
+}
+
 static DWORD overlapped_wait_all(acr_file_t *f, DWORD *nbytes)
 {
     DWORD ws;

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c?rev=884551&r1=884550&r2=884551&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c Thu Nov 26 
13:19:25 2009
@@ -392,7 +392,6 @@
 {
     int rc =  0;
     int fo;
-    jobject od;
 
     fo = acr_ioh_open(fp, ACR_DT_FILE, 0, file_cleanup);
     if (fo < 0) {
@@ -400,27 +399,17 @@
         goto finally;
     }
     /* Create File Descriptor Object */
-    od = ACR_DescriptorCreate(_E, ACR_DT_FILE, fo, NULL,
-                              descriptor_cleanup);
-    if (!od) {
-        rc = ACR_GET_OS_ERROR();
-        goto finally;
-    }
-    /* Create Pipe object */
-    fp->descriptor = (*_E)->NewWeakGlobalRef(_E, *fdo);
-    *fdo = ACR_NewPipeObject(_E, flags, od, NULL);
+    *fdo = ACR_DescriptorCreate(_E, ACR_DT_FILE, fo, NULL,
+                                descriptor_cleanup);
     if (!*fdo) {
         rc = ACR_GET_OS_ERROR();
         goto finally;
     }
-finally:
-    if (rc) {
-        if (fp && fp->descriptor)
-            (*_E)->DeleteWeakGlobalRef(_E, fp->descriptor);
-        /* ### close the fp */
-        x_free(fp);
-    }
+    fp->descriptor = (*_E)->NewWeakGlobalRef(_E, *fdo);
 
+finally:
+    if (rc)
+        file_cleanup(fp, ACR_DT_FILE, ACR_IOH_CLEAR);
     return rc;
 }
 
@@ -451,25 +440,18 @@
         ACR_THROW_IO_IF_ERR(rc);
         return NULL;
     }
-    rc = do_popen(_E, pd[0], flags & ACR_PIPE_RD,  &fd[0]);
+    rc = do_popen(_E, pd[0], flags & ACR_PIPE_RD, &fd[0]);
     if (rc) {
-        goto cleanup;
+        goto finally;
     }
     rc = do_popen(_E, pd[1], flags & ACR_PIPE_WR, &fd[1]);
     if (rc) {
-        /* ### fd[0] will be closed by GC ?
-         */
-        pd[0] = NULL;
-        goto cleanup;
+        ACR_DescriptorCleanup(_E, fd[0]);
+        goto finally;
     }
-    return ACR_NewPipeObject(_E, flags, fd[0], fd[1], NULL);
-
-cleanup:
-    if (pd[0])
-        file_cleanup(pd[0], ACR_DT_FILE, ACR_IOH_CLEAR);
-    if (pd[1])
-        file_cleanup(pd[1], ACR_DT_FILE, ACR_IOH_CLEAR);
+    return ACR_NewPipeObject(_E, flags, fd[0], fd[1], pd[0]->name);
 
+finally:
     ACR_THROW_IO_IF_ERR(rc);
     return NULL;
 }


Reply via email to