]> sourceware.org Git - newlib-cygwin.git/commitdiff
Cygwin: FIFO: use a retry loop when opening a writer
authorKen Brown <kbrown@cornell.edu>
Sun, 14 Apr 2019 19:16:02 +0000 (19:16 +0000)
committerCorinna Vinschen <corinna@vinschen.de>
Tue, 16 Apr 2019 10:54:43 +0000 (12:54 +0200)
There may be short periods when there's no pipe instance available.
Keep trying.

winsup/cygwin/fhandler_fifo.cc

index 479021e8e88ceb69d90c69b08e8085cc613e71f0..d4d2b3883ba1389875b045af91b3160ec0b8645a 100644 (file)
@@ -30,6 +30,12 @@ STATUS_PIPE_EMPTY simply means there's no data to be read. */
                   || _s == STATUS_PIPE_BROKEN \
                   || _s == STATUS_PIPE_EMPTY; })
 
+#define STATUS_PIPE_NO_INSTANCE_AVAILABLE(status)      \
+               ({ NTSTATUS _s = (status); \
+                  _s == STATUS_INSTANCE_NOT_AVAILABLE \
+                  || _s == STATUS_PIPE_NOT_AVAILABLE \
+                  || _s == STATUS_PIPE_BUSY; })
+
 fhandler_fifo::fhandler_fifo ():
   fhandler_base (), read_ready (NULL), write_ready (NULL),
   listen_client_thr (NULL), lct_termination_evt (NULL), nhandlers (0),
@@ -543,28 +549,32 @@ fhandler_fifo::open (int flags, mode_t)
      listen_client thread is running.  Then signal write_ready.  */
   if (writer)
     {
-      if (!wait (read_ready))
-       {
-         res = error_errno_set;
-         goto out;
-       }
-      NTSTATUS status = open_pipe ();
-      if (!NT_SUCCESS (status))
-       {
-         debug_printf ("create of writer failed");
-         __seterrno_from_nt_status (status);
-         res = error_errno_set;
-         goto out;
-       }
-      else if (!arm (write_ready))
+      while (1)
        {
-         res = error_set_errno;
-         goto out;
-       }
-      else
-       {
-         set_pipe_non_blocking (get_handle (), true);
-         res = success;
+         if (!wait (read_ready))
+           {
+             res = error_errno_set;
+             goto out;
+           }
+         NTSTATUS status = open_pipe ();
+         if (NT_SUCCESS (status))
+           {
+             set_pipe_non_blocking (get_handle (), true);
+             if (!arm (write_ready))
+               res = error_set_errno;
+             else
+               res = success;
+             goto out;
+           }
+         else if (STATUS_PIPE_NO_INSTANCE_AVAILABLE (status))
+           Sleep (1);
+         else
+           {
+             debug_printf ("create of writer failed");
+             __seterrno_from_nt_status (status);
+             res = error_errno_set;
+             goto out;
+           }
        }
     }
 out:
This page took 0.037365 seconds and 5 git commands to generate.