From 70e60d969c4006ddce3a4e16549d0271158ba8f4 Mon Sep 17 00:00:00 2001 From: Ken Brown Date: Tue, 22 Jan 2019 15:09:35 -0500 Subject: [PATCH FIFO, draft 0/4] Allow a FIFO to have multiple writers Currently a FIFO can have only one writer. A second attempt to open the FIFO for writing blocks while fhandler_fifo::open waits for the read_ready event to be signalled. This patch series tries to fix the problem by having the reader open multiple instances of the Windows named pipe underlying the FIFO. When the FIFO is opened for reading, a 'listen_client' thread is created that runs until the FIFO is closed. This thread listens for clients (writers) to connect to the pipe, and it creates new pipe instances as needed. fhandler_fifo::raw_read loops through the connected writers, checking for input. Much remains to be implemented (see below), but preliminary testing of the current draft seems to work as expected. I've tested it by running the fifo client and server programs from Chapter 44 of the book "The Linux Programming Interface: Linux and UNIX System Programming Handbook" by Michael Kerrisk. (See https://cygwin.com/ml/cygwin/2015-03/msg00047.html for simplified versions of these programs. These work as on Linux.) I've also tried the test given in http://www.cygwin.org/ml/cygwin/2015-12/msg00311.html. This doesn't fully succeed, but I think the failure results from some of the fhandler_fifo methods that I haven't fully implemented yet. What happens is that fifo1.sh in Terminal 1 is correctly unblocked when I run fifo2.sh in Terminal 2, but fifo2.sh gives the following error: -bash: read: read error: 0: Bad file descriptor I hope to fix that soon. TODO: - Make whatever changes are needed in the fhandler_fifo methods that I haven't touched yet. I hope these changes will fix the "Bad file descriptor" error mentioned above. - Think about whether shared memory is needed in case several file descriptors refer to the same FIFO opened for reading. - Try to get the code to work for duplexers (FIFOs opened for reading and writing). I haven't thought about this at all yet. Ken Brown (4): Cygwin: fhandler_fifo: allow unlimited pipe_instances Cygwin: fhandler_fifo: Allow multiple writers Cygwin: adapt fhandler_fifo::close to recent changes Cygwin: fhandler_fifo: add a spinlock winsup/cygwin/fhandler.h | 23 +- winsup/cygwin/fhandler_fifo.cc | 426 ++++++++++++++++++++++++++------- winsup/cygwin/fhandler_pipe.cc | 11 +- 3 files changed, 369 insertions(+), 91 deletions(-) -- 2.17.0