]> sourceware.org Git - newlib-cygwin.git/commitdiff
* fhandler.cc (fhandler_base::wait_overlapped): Reorganize to eliminate gotos
authorChristopher Faylor <me@cgf.cx>
Sat, 20 Dec 2008 19:20:00 +0000 (19:20 +0000)
committerChristopher Faylor <me@cgf.cx>
Sat, 20 Dec 2008 19:20:00 +0000 (19:20 +0000)
and to hopefully eliminate one race when a signal is detected or there is a
WFMO error.

winsup/cygwin/ChangeLog
winsup/cygwin/fhandler.cc

index 13499c04171b71e3fd533dc561e7836e09805f3e..2d12203e7d6541b54e1e988a90db4de8f363e38d 100644 (file)
@@ -1,3 +1,9 @@
+2008-12-20  Christopher Faylor  <me+cygwin@cgf.cx>
+
+       * fhandler.cc (fhandler_base::wait_overlapped): Reorganize to eliminate
+       gotos and to hopefully eliminate one race when a signal is detected or
+       there is a WFMO error.
+
 2008-12-20  Christopher Faylor  <me+cygwin@cgf.cx>
 
        * pinfo.h (pinfo::thisproc): Declare.  Rename from set_myself.
index 5c1430fdff55692dabff25047d6cc0d717b8ca92..b573e4eca98fc406356ff45441670286212189bd 100644 (file)
@@ -1682,19 +1682,11 @@ fhandler_base::destroy_overlapped ()
 int
 fhandler_base::wait_overlapped (bool inres, bool writing, DWORD *bytes)
 {
-  int res;
+  int res = 0;
   *bytes = (DWORD) -1;
-  DWORD err = GetLastError ();
-  if (!inres && err != ERROR_IO_PENDING)
-    {
-      if (err != ERROR_HANDLE_EOF && err != ERROR_BROKEN_PIPE)
-       goto err;
-      res = 1;
-      *bytes = 0;
-      err = 0;
-    }
-  else
-    {
+  DWORD err;
+  if (inres || ((err = GetLastError ()) == ERROR_IO_PENDING))
+   {
 #ifdef DEBUGGING
       if (!get_overlapped ())
        system_printf ("get_overlapped is zero?");
@@ -1707,39 +1699,47 @@ fhandler_base::wait_overlapped (bool inres, bool writing, DWORD *bytes)
       if (&_my_tls == _main_tls)
        w4[n++] = signal_arrived;
       HANDLE h = writing ? get_output_handle () : get_handle ();
-      DWORD wres = WaitForMultipleObjects (n, w4, false, INFINITE);
-      err = 0;
-      switch (wres)
+      DWORD wfres = WaitForMultipleObjects (n, w4, false, INFINITE);
+      if (wfres != WAIT_OBJECT_0)
+       CancelIo (h);
+      BOOL wores = GetOverlappedResult (h, get_overlapped (), bytes, false);
+      bool signalled = !wores && (wfres == WAIT_OBJECT_0 + 1);
+      if (signalled)
        {
-       case WAIT_OBJECT_0:
-         debug_printf ("normal read");
-         if (GetOverlappedResult (h, get_overlapped (), bytes, false))
-           res = 1;
-         else
-           {
-             err = GetLastError ();
-             goto err;
-           }
-         break;
-       case WAIT_OBJECT_0 + 1:
          debug_printf ("got a signal");
-         CancelIo (h);
          set_errno (EINTR);
          res = 0;
-         break;
-       default:
+         err = 0;
+       }
+      else if (!wores)
+       {
          err = GetLastError ();
-         debug_printf ("WFMO error, %E");
-         goto err;
-         break;
+         debug_printf ("general error");
+       }
+      else
+       {
+         debug_printf ("normal read");
+         res = 1;
+         err = 0;
        }
     }
-  goto out;
 
-err:
-  __seterrno_from_win_error (err);
-  res = -1;
-out:
+  if (!err)
+    /* nothing to do */;
+  else if (err != ERROR_HANDLE_EOF && err != ERROR_BROKEN_PIPE)
+    {
+      debug_printf ("err %u", err);
+      __seterrno_from_win_error (err);
+      res = -1;
+    }
+  else
+    {
+      res = 1;
+      *bytes = 0;
+      err = 0;
+      debug_printf ("EOF");
+    }
+
   /* Make sure the event is unsignalled (this is a potential race in a multi-threaded
      app.  Sigh.).  Must do this after WFMO and GetOverlappedResult or suffer
      occasional sporadic problems:
This page took 0.03796 seconds and 5 git commands to generate.