From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id E59F73857C71; Tue, 14 Sep 2021 15:04:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E59F73857C71 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: fhandler_pipe: control blocking mode of the Windows pipe X-Act-Checkin: newlib-cygwin X-Git-Author: Ken Brown X-Git-Refname: refs/heads/master X-Git-Oldrev: 4b25687ea3ee2fc6c79e2df999a2fa86fcd39e67 X-Git-Newrev: d0ad52aa6eb1a47ebb76a11118b19aa70e2671f0 Message-Id: <20210914150448.E59F73857C71@sourceware.org> Date: Tue, 14 Sep 2021 15:04:48 +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, 14 Sep 2021 15:04:49 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=d0ad52aa6eb1a47ebb76a11118b19aa70e2671f0 commit d0ad52aa6eb1a47ebb76a11118b19aa70e2671f0 Author: Ken Brown Date: Sat May 25 13:05:49 2019 -0400 Cygwin: fhandler_pipe: control blocking mode of the Windows pipe Add methods 'set_pipe_non_blocking' and 'fcntl' to keep the blocking mode of the Windows pipe in sync with that of the fhandler_pipe object. This applies to pipes created with the 'pipe' and 'pipe2' system calls. Diff: --- winsup/cygwin/fhandler.h | 2 ++ winsup/cygwin/fhandler_pipe.cc | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 12618db58..5873bb6be 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -1243,6 +1243,7 @@ class fhandler_pipe: public fhandler_base private: pid_t popen_pid; size_t max_atomic_write; + void set_pipe_non_blocking (bool nonblocking); public: fhandler_pipe (); @@ -1260,6 +1261,7 @@ public: void __reg3 raw_read (void *ptr, size_t& len); ssize_t __reg3 raw_write (const void *ptr, size_t len); int ioctl (unsigned int cmd, void *); + int fcntl (int cmd, intptr_t); int __reg2 fstat (struct stat *buf); int __reg2 fstatvfs (struct statvfs *buf); int __reg3 fadvise (off_t, off_t, int); diff --git a/winsup/cygwin/fhandler_pipe.cc b/winsup/cygwin/fhandler_pipe.cc index 61ab29187..75435b009 100644 --- a/winsup/cygwin/fhandler_pipe.cc +++ b/winsup/cygwin/fhandler_pipe.cc @@ -35,6 +35,23 @@ fhandler_pipe::fhandler_pipe () need_fork_fixup (true); } +/* This also sets the pipe's read mode to byte_stream unconditionally. */ +void +fhandler_pipe::set_pipe_non_blocking (bool nonblocking) +{ + NTSTATUS status; + IO_STATUS_BLOCK io; + FILE_PIPE_INFORMATION fpi; + + fpi.ReadMode = FILE_PIPE_BYTE_STREAM_MODE; + fpi.CompletionMode = nonblocking ? FILE_PIPE_COMPLETE_OPERATION + : FILE_PIPE_QUEUE_OPERATION; + status = NtSetInformationFile (get_handle (), &io, &fpi, sizeof fpi, + FilePipeInformation); + if (!NT_SUCCESS (status)) + debug_printf ("NtSetInformationFile(FilePipeInformation): %y", status); +} + int fhandler_pipe::init (HANDLE f, DWORD a, mode_t mode, int64_t uniq_id) { @@ -62,8 +79,7 @@ fhandler_pipe::init (HANDLE f, DWORD a, mode_t mode, int64_t uniq_id) set_ino (uniq_id); set_unique_id (uniq_id | !!(mode & GENERIC_WRITE)); if (opened_properly) - /* ... */ - ; + set_pipe_non_blocking (is_nonblocking ()); return 1; } @@ -612,6 +628,20 @@ fhandler_pipe::ioctl (unsigned int cmd, void *p) return 0; } +int +fhandler_pipe::fcntl (int cmd, intptr_t arg) +{ + if (cmd != F_SETFL) + 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 (now_nonblocking); + return res; +} + int __reg2 fhandler_pipe::fstat (struct stat *buf) {