Cygwin: FIFO: code simplification

There are currently three functions that call NtQueryInformationFile
to determine the state of a pipe instance.  Do this only once, in a
new fifo_client_handler::set_state () function, and call that when
state information is needed.

Remove the fifo_client_handler methods pipe_state and get_state, which
are no longer needed.

Make fhandler_fifo::get_fc_handler return a reference, for use in
select.cc:peek_fifo.

Make other small changes to ensure that this commit doesn't change any
decisions based on the state of a fifo_client_handler.

The tricky part is interpreting FILE_PIPE_CLOSING_STATE, which we
translate to fc_closing.  Our current interpretation, which is not
changing as a result of this commit, is that the writer at the other
end of the pipe instance is viewed as still connected from the point
of view of raw_read and determining EOF.

But it is not viewed as still connected if we are deciding whether to
unblock a new reader that is trying to open.
This commit is contained in:
Ken Brown
2020-05-09 17:25:39 -04:00
parent 2125ca8a69
commit 1f27345947
3 changed files with 44 additions and 67 deletions

View File

@ -871,32 +871,16 @@ peek_fifo (select_record *s, bool from_select)
fh->fifo_client_lock ();
int nconnected = 0;
for (int i = 0; i < fh->get_nhandlers (); i++)
if (fh->get_fc_handler (i).get_state () >= fc_connected)
if (fh->get_fc_handler (i).set_state () >= fc_closing)
{
nconnected++;
switch (fh->get_fc_handler (i).pipe_state ())
if (fh->get_fc_handler (i).state == fc_input_avail)
{
case FILE_PIPE_CONNECTED_STATE:
fh->get_fc_handler (i).get_state () = fc_connected;
break;
case FILE_PIPE_DISCONNECTED_STATE:
fh->get_fc_handler (i).get_state () = fc_disconnected;
nconnected--;
break;
case FILE_PIPE_CLOSING_STATE:
fh->get_fc_handler (i).get_state () = fc_closing;
break;
case FILE_PIPE_INPUT_AVAILABLE_STATE:
fh->get_fc_handler (i).get_state () = fc_input_avail;
select_printf ("read: %s, ready for read", fh->get_name ());
fh->fifo_client_unlock ();
fh->reading_unlock ();
gotone += s->read_ready = true;
goto out;
default:
fh->get_fc_handler (i).get_state () = fc_error;
nconnected--;
break;
}
}
fh->maybe_eof (!nconnected);