[PATCH 09/14] Cygwin: FIFO: fix the use of the read_ready event

2019-04-14 Thread Ken Brown
Make read_ready a manual reset event. It should always be set shortly after startup of the listen_client thread and remain set until the thread terminates. (We don't want writers to connect without being recorded in the client handler list.) Remove the unnecessary code that checks for

[PATCH 12/14] Cygwin: FIFO: start the listen_client thread when duping a reader

2019-04-14 Thread Ken Brown
Otherwise it doesn't get started until the dup'd fd tries to read, which delays client connections. --- winsup/cygwin/fhandler_fifo.cc | 22 +- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc index

[PATCH 14/14] Cygwin: FIFO: fix and simplify listen_client_thread

2019-04-14 Thread Ken Brown
Remove fifo_client_handler::connect and move its code into listen_client_thread. That way we can check the return status when a client handler's connect_evt is signaled. Previously we incorrectly assumed there was a successful connection. Also simplify listen_client_thread in the following

[PATCH 01/14] Cygwin: FIFO: rename client[] to fc_handler[]

2019-04-14 Thread Ken Brown
The word "client" suggests something that holds a handle to the client side of the pipe (in Windows terminology). But our fifo_client_handlers hold a handle the server side of the pipe, and they *connect* to clients. --- winsup/cygwin/fhandler.h | 20 +++ winsup/cygwin/fhandler_fifo.cc

[PATCH 08/14] Cygwin: FIFO: fix fifo_client_handler::close

2019-04-14 Thread Ken Brown
Make sure that fhandler_base::close rather than fhandler_fifo::close is called on the fhandler. Also, delete the fhandler, since we allocated it. --- winsup/cygwin/fhandler_fifo.cc | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/fhandler_fifo.cc

[PATCH 05/14] Cygwin: FIFO: fix the error checking in raw_read

2019-04-14 Thread Ken Brown
If the pipe is empty, we can get either ERROR_NO_DATA or ERROR_PIPE_LISTENING. --- winsup/cygwin/fhandler_fifo.cc | 13 + 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc index 764420ffd..2da579b95 100644 ---

[PATCH 03/14] Cygwin: FIFO: remember the type of the fhandler

2019-04-14 Thread Ken Brown
Add data members 'reader', 'writer', and 'duplexer' to the fhandler_fifo class. Set them in fhandler_fifo::open. ('duplexer' replaces the previous '_duplexer'.) This will be useful in later commits. --- winsup/cygwin/fhandler.h | 2 +- winsup/cygwin/fhandler_fifo.cc | 14 --

[PATCH 00/14] FIFO bug fixes and code simplifications

2019-04-14 Thread Ken Brown
Ken Brown (14): Cygwin: FIFO: rename client[] to fc_handler[] Cygwin: FIFO: hit_eof: add a call to fifo_client_lock Cygwin: FIFO: remember the type of the fhandler Cygwin: FIFO: fix a thinko in listen_client_thread Cygwin: FIFO: fix the error checking in raw_read Cygwin: check for

[PATCH 11/14] Cygwin: FIFO: fix clone

2019-04-14 Thread Ken Brown
After copyto is called, make the new fhandler's pipe_name point to the new fhandler's pipe_name_buf, which is a *copy* of the old fhandler's pipe_name_buf. Previously, get_pipe_name would return the wrong result after a clone/dup, causing create_pipe_instance and open_pipe to fail. Also, stop

[PATCH 13/14] Cygwin: FIFO: improve raw_write

2019-04-14 Thread Ken Brown
Don't set the write end of the pipe to non-blocking mode if the FIFO is opened in blocking mode. In fhandler_fifo::raw_write in blocking mode, wait for the write to complete rather than returning -1 with EAGAIN. If the amount to write is large, write in smaller chunks (of size determined by a

[PATCH 07/14] Cygwin: FIFO: code simplification: don't overload get_handle

2019-04-14 Thread Ken Brown
Rename fhandler_fifo::get_handle(int) to get_fc_handle(int), and remove fhandler_fifo::get_handle(void). --- winsup/cygwin/fhandler.h | 7 --- winsup/cygwin/select.cc | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h

[PATCH 06/14] Cygwin: check for STATUS_PENDING in fhandler_base::raw_read

2019-04-14 Thread Ken Brown
If NtReadFile returns STATUS_PENDING, wait for the read to complete. This can happen, for instance, in the case of a FIFO opened with O_RDRW. --- winsup/cygwin/fhandler.cc | 14 +- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/fhandler.cc

[PATCH 02/14] Cygwin: FIFO: hit_eof: add a call to fifo_client_lock

2019-04-14 Thread Ken Brown
The second check of nconnected needs to be protected by a lock as well as the first. --- winsup/cygwin/fhandler_fifo.cc | 21 + 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc index

[PATCH 10/14] Cygwin: FIFO: use a retry loop when opening a writer

2019-04-14 Thread Ken Brown
There may be short periods when there's no pipe instance available. Keep trying. --- winsup/cygwin/fhandler_fifo.cc | 52 -- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc index

[PATCH 04/14] Cygwin: FIFO: fix a thinko in listen_client_thread

2019-04-14 Thread Ken Brown
--- winsup/cygwin/fhandler_fifo.cc | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc index 258c3cf8a..764420ffd 100644 --- a/winsup/cygwin/fhandler_fifo.cc +++ b/winsup/cygwin/fhandler_fifo.cc @@ -362,7 +362,10