]> sourceware.org Git - newlib-cygwin.git/commit
Cygwin: pipe: Use read pipe handle for select() on write pipe.
authorTakashi Yano <takashi.yano@nifty.ne.jp>
Tue, 14 Sep 2021 10:10:48 +0000 (19:10 +0900)
committerCorinna Vinschen <corinna@vinschen.de>
Tue, 14 Sep 2021 11:01:40 +0000 (13:01 +0200)
commitf79a46112e7c43858203536955ad41af701b4a0f
tree0d2e6058e8888abf34cbd006736d50640e68a6e3
parent0d12015670a00b7ecb2db4f66368e863b68de13d
Cygwin: pipe: Use read pipe handle for select() on write pipe.

- Usually WriteQuotaAvailable retrieved by NtQueryInformationFile()
  on the write side reflects the space available in the inbound buffer
  on the read side. However, if a pipe read is currently pending,
  WriteQuotaAvailable on the write side is decremented by the number
  of bytes the read side is requesting. So it's possible (even likely)
  that WriteQuotaAvailable is 0, even if the inbound buffer on the
  read side is not full. This can lead to a deadlock situation:
  The reader is waiting for data, but select on the writer side
  assumes that no space is available in the read side inbound buffer.

  Currently, to avoid this stuation, read() does not request larger
  block than pipe size - 1. However, this mechanism does not take
  effect if the reader side is non-cygwin app.

  The only reliable information is available on the read side, so
  fetch info from the read side via the pipe-specific query handle
  (query_hdl) introduced.

  If the query_hdl (read handle) is kept in write side, writer can
  not detect closure of read pipe. Therefore, raw_write() counts
  write handle and query_hdl. If they are equal, only the pairs of
  write handle and query_hdl are alive. In this case, raw_write()
  returns EPIPE and raises SIGPIPE.

- Nonblocking pipes (PIPE_NOWAIT) are not well handled by non-Cygwin
  tools, so convert pipe handles to PIPE_WAIT handles when spawning
  a non-Cygwin process.
winsup/cygwin/fhandler.h
winsup/cygwin/fhandler_pipe.cc
winsup/cygwin/select.cc
winsup/cygwin/spawn.cc
This page took 0.495921 seconds and 5 git commands to generate.