From a9b2ac60c8691bd75ddb642b965b65519deb2f11 Mon Sep 17 00:00:00 2001 From: Ken Brown Date: Sun, 13 Jan 2019 11:15:50 -0500 Subject: [PATCH FIFO, draft 1/4] Cygwin: fhandler_fifo: allow unlimited pipe_instances Give fhandler_pipe::create new optional parameters 'max_instances' (= 1 by default) and first_instance (= true by default). Use FILE_FLAG_FIRST_PIPE_INSTANCE only if first_instance is true. Change the create_pipe macro for fhandler_fifo to call fhandler_pipe::create with max_instances = PIPE_UNLIMITED_INSTANCES. --- winsup/cygwin/fhandler.h | 3 ++- winsup/cygwin/fhandler_fifo.cc | 9 +++++---- winsup/cygwin/fhandler_pipe.cc | 11 +++++++---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 7e460701c..5ff00c4d7 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -1212,7 +1212,8 @@ public: int init (HANDLE, DWORD, mode_t, int64_t); static int create (fhandler_pipe *[2], unsigned, int); static DWORD create (LPSECURITY_ATTRIBUTES, HANDLE *, HANDLE *, DWORD, - const char *, DWORD, int64_t *unique_id = NULL); + const char *, DWORD, int64_t *unique_id = NULL, + DWORD max_instances = 1, bool first_instance = true); fhandler_pipe (void *) {} void copyto (fhandler_base *x) diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc index 5733ec778..b171719b1 100644 --- a/winsup/cygwin/fhandler_fifo.cc +++ b/winsup/cygwin/fhandler_fifo.cc @@ -31,8 +31,9 @@ fhandler_fifo::fhandler_fifo (): #define fnevent(w) fifo_name (npbuf, w "-event") #define fnpipe() fifo_name (npbuf, "fifo") -#define create_pipe(r, w) \ - fhandler_pipe::create (sa_buf, (r), (w), 0, fnpipe (), open_mode) +#define create_pipe(r, w, f) \ + fhandler_pipe::create (sa_buf, (r), (w), 0, fnpipe (), open_mode, \ + NULL, PIPE_UNLIMITED_INSTANCES, (f)) char * fhandler_fifo::fifo_name (char *buf, const char *what) @@ -137,7 +138,7 @@ fhandler_fifo::open (int flags, mode_t) FIXME: Probably need to special case O_RDWR case. */ if (!reader) /* We are not a reader */; - else if (create_pipe (&get_io_handle (), NULL)) + else if (create_pipe (&get_io_handle (), NULL, true)) { debug_printf ("create of reader failed"); res = error_set_errno; @@ -170,7 +171,7 @@ fhandler_fifo::open (int flags, mode_t) res = error_errno_set; goto out; } - else if ((err = create_pipe (NULL, &get_io_handle ())) == 0) + else if ((err = create_pipe (NULL, &get_io_handle (), false)) == 0) break; else if (err == ERROR_PIPE_BUSY) { diff --git a/winsup/cygwin/fhandler_pipe.cc b/winsup/cygwin/fhandler_pipe.cc index eafaa8856..f09035f16 100644 --- a/winsup/cygwin/fhandler_pipe.cc +++ b/winsup/cygwin/fhandler_pipe.cc @@ -216,7 +216,8 @@ fhandler_pipe::dup (fhandler_base *child, int flags) DWORD fhandler_pipe::create (LPSECURITY_ATTRIBUTES sa_ptr, PHANDLE r, PHANDLE w, DWORD psize, const char *name, DWORD open_mode, - int64_t *unique_id) + int64_t *unique_id, DWORD max_instances, + bool first_instance) { /* Default to error. */ if (r) @@ -246,7 +247,9 @@ fhandler_pipe::create (LPSECURITY_ATTRIBUTES sa_ptr, PHANDLE r, PHANDLE w, if (name) len += __small_sprintf (pipename + len, "%s", name); - open_mode |= PIPE_ACCESS_INBOUND | FILE_FLAG_FIRST_PIPE_INSTANCE; + open_mode |= PIPE_ACCESS_INBOUND; + if (first_instance) + open_mode |= FILE_FLAG_FIRST_PIPE_INSTANCE; /* Retry CreateNamedPipe as long as the pipe name is in use. Retrying will probably never be necessary, but we want @@ -281,8 +284,8 @@ fhandler_pipe::create (LPSECURITY_ATTRIBUTES sa_ptr, PHANDLE r, PHANDLE w, definitely required for pty handling since fhandler_pty_master writes to the pipe in chunks, terminated by newline when CANON mode is specified. */ - *r = CreateNamedPipe (pipename, open_mode, pipe_mode, 1, psize, - psize, NMPWAIT_USE_DEFAULT_WAIT, sa_ptr); + *r = CreateNamedPipe (pipename, open_mode, pipe_mode, max_instances, + psize, psize, NMPWAIT_USE_DEFAULT_WAIT, sa_ptr); if (*r != INVALID_HANDLE_VALUE) { -- 2.17.0