From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2210) id C316D385041D; Tue, 4 Aug 2020 15:29:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C316D385041D Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Ken Brown To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: FIFO: don't read from pipes that are closing X-Act-Checkin: newlib-cygwin X-Git-Author: Ken Brown X-Git-Refname: refs/heads/master X-Git-Oldrev: 289af73a896b110580e237ecfdf044dcdc2f5066 X-Git-Newrev: 251624a3529c3d0d3d9cdb5fbaf4c3e9b079c894 Message-Id: <20200804152936.C316D385041D@sourceware.org> Date: Tue, 4 Aug 2020 15:29:36 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Aug 2020 15:29:36 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=251624a3529c3d0d3d9cdb5fbaf4c3e9b079c894 commit 251624a3529c3d0d3d9cdb5fbaf4c3e9b079c894 Author: Ken Brown Date: Mon Aug 3 09:35:00 2020 -0400 Cygwin: FIFO: don't read from pipes that are closing Don't try to read from fifo_client_handlers that are in the fc_closing state. Experiments have shown that this always yields STATUS_PIPE_BROKEN, so it just wastes a Windows system call. Re-order the values in enum fifo_client_connect_state to reflect the new status of fc_closing. Diff: --- winsup/cygwin/fhandler.h | 9 +-------- winsup/cygwin/fhandler_fifo.cc | 6 +++--- winsup/cygwin/select.cc | 2 +- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index f64eabda4..40e201b0f 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -1276,20 +1276,13 @@ public: #define CYGWIN_FIFO_PIPE_NAME_LEN 47 -/* We view the fc_closing state as borderline between open and closed - for a writer at the other end of a fifo_client_handler. - - We still attempt to read from the writer when the handler is in - this state, and we don't declare a reader to be at EOF if there's a - handler in this state. But the existence of a handler in this - state is not sufficient to unblock a reader trying to open. */ enum fifo_client_connect_state { fc_unknown, fc_error, fc_disconnected, - fc_listening, fc_closing, + fc_listening, fc_connected, fc_input_avail, }; diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc index c816c692a..1e1140f53 100644 --- a/winsup/cygwin/fhandler_fifo.cc +++ b/winsup/cygwin/fhandler_fifo.cc @@ -365,7 +365,7 @@ fhandler_fifo::cleanup_handlers () while (i < nhandlers) { - if (fc_handler[i].get_state () < fc_closing) + if (fc_handler[i].get_state () < fc_connected) delete_client_handler (i); else i++; @@ -1280,7 +1280,7 @@ fhandler_fifo::raw_read (void *in_ptr, size_t& len) for (j = 0; j < nhandlers; j++) if (fc_handler[j].last_read) break; - if (j < nhandlers && fc_handler[j].get_state () >= fc_closing) + if (j < nhandlers && fc_handler[j].get_state () >= fc_connected) { NTSTATUS status; IO_STATUS_BLOCK io; @@ -1315,7 +1315,7 @@ fhandler_fifo::raw_read (void *in_ptr, size_t& len) /* Second pass. */ for (int i = 0; i < nhandlers; i++) - if (fc_handler[i].get_state () >= fc_closing) + if (fc_handler[i].get_state () >= fc_connected) { NTSTATUS status; IO_STATUS_BLOCK io; diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc index 0c94f6c45..9ee305f64 100644 --- a/winsup/cygwin/select.cc +++ b/winsup/cygwin/select.cc @@ -878,7 +878,7 @@ peek_fifo (select_record *s, bool from_select) { fifo_client_handler &fc = fh->get_fc_handler (i); fc.query_and_set_state (); - if (fc.get_state () >= fc_closing) + if (fc.get_state () >= fc_connected) { nconnected++; if (fc.get_state () == fc_input_avail)