public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: FIFO: synchronize the blocking mode of a writer's pipe
@ 2019-04-26 11:56 Ken Brown
  0 siblings, 0 replies; only message in thread
From: Ken Brown @ 2019-04-26 11:56 UTC (permalink / raw)
  To: cygwin-cvs

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=440559c40a4879ddfe0a73282aab994c53955cef

commit 440559c40a4879ddfe0a73282aab994c53955cef
Author: Ken Brown <kbrown@cornell.edu>
Date:   Thu Apr 25 18:21:11 2019 -0400

    Cygwin: FIFO: synchronize the blocking mode of a writer's pipe
    
    The blocking mode of the Windows pipe underlying a writer is set to
    match that of the writer itself when the latter is opened.  Define
    fhandler_fifo::fcntl to keep the pipe and the writer in sync if the
    blocking mode is changed via fcntl.

Diff:
---
 winsup/cygwin/fhandler.h       |  1 +
 winsup/cygwin/fhandler_fifo.cc | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 0df25aa..f5ed61c 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -1294,6 +1294,7 @@ public:
   int open (int, mode_t);
   off_t lseek (off_t offset, int whence);
   int close ();
+  int fcntl (int cmd, intptr_t);
   int dup (fhandler_base *child, int);
   bool isfifo () const { return true; }
   void set_close_on_exec (bool val);
diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc
index ac2196c..a1e395b 100644
--- a/winsup/cygwin/fhandler_fifo.cc
+++ b/winsup/cygwin/fhandler_fifo.cc
@@ -891,6 +891,22 @@ fhandler_fifo::close ()
   return fhandler_base::close () || ret;
 }
 
+/* If we're a writer, keep the nonblocking state of the windows pipe
+   in sync with our nonblocking state. */
+int
+fhandler_fifo::fcntl (int cmd, intptr_t arg)
+{
+  if (cmd != F_SETFL || !writer)
+    return fhandler_base::fcntl (cmd, arg);
+
+  const bool was_nonblocking = is_nonblocking ();
+  int res = fhandler_base::fcntl (cmd, arg);
+  const bool now_nonblocking = is_nonblocking ();
+  if (now_nonblocking != was_nonblocking)
+    set_pipe_non_blocking (get_handle (), now_nonblocking);
+  return res;
+}
+
 int
 fhandler_fifo::dup (fhandler_base *child, int flags)
 {


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-04-26 11:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-26 11:56 [newlib-cygwin] Cygwin: FIFO: synchronize the blocking mode of a writer's pipe Ken Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).