Cygwin: FIFO: add a timeout to take_ownership

fhandler_fifo::take_ownership() is called from select.cc::peek_fifo
and fhandler_fifo::raw_read and could potentially block indefinitely
if something goes wrong.  This is always undesirable in peek_fifo, and
it is undesirable in a nonblocking read.  Fix this by adding a timeout
parameter to take_ownership.

Arbitrarily use a 1 ms timeout in peek_fifo and a 10 ms timeout in
raw_read.  These numbers may have to be tweaked based on experience.

Replace the call to cygwait in take_ownership by a call to WFSO.
There's no need to allow interruption now that we have a timeout.
This commit is contained in:
Ken Brown
2020-08-03 09:17:06 -04:00
parent 6acce025d0
commit 6ed067a0ae
3 changed files with 30 additions and 53 deletions

View File

@@ -867,16 +867,11 @@ peek_fifo (select_record *s, bool from_select)
}
fh->reading_lock ();
if (fh->take_ownership () != WAIT_OBJECT_0)
if (fh->take_ownership (1) < 0)
{
select_printf ("%s, unable to take ownership", fh->get_name ());
fh->reading_unlock ();
gotone += s->read_ready = true;
if (s->except_selected)
gotone += s->except_ready = true;
goto out;
}
fh->fifo_client_lock ();
int nconnected = 0;
for (int i = 0; i < fh->get_nhandlers (); i++)