From 5e8e21d938b5410b008f20d50d8d0fb9ba6df66b Mon Sep 17 00:00:00 2001 From: Egor Duda Date: Sun, 18 Mar 2001 18:05:01 +0000 Subject: * fhandler.h (fhandler_tty_slave): Declare new methods. * select.cc (fhandler_tty_slave::select_read): New method. * select.cc (fhandler_tty_slave::ready_for_read): Ditto. * select.cc (verify_tty_slave): New function. * fhandler_termios.cc (fhandler_termios::line_edit): Empty input buffer on signal. * fhandler_tty.cc (fhandler_tty_slave::read): Check for input data after reading from pipe. Reset event if input pipe is empty. * tty.h (class tty): Allow creating events with manual reset. * tty.cc (tty::get_event): Use manual_reset flag. * tty.cc (tty::common_init): Create input_available_event with manual reset. --- winsup/cygwin/fhandler_tty.cc | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'winsup/cygwin/fhandler_tty.cc') diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 5cca97b4d..a2e815e66 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -614,6 +614,7 @@ fhandler_tty_slave::read (void *ptr, size_t len) size_t readlen; DWORD bytes_in_pipe; char buf[INP_BUFFER_SIZE]; + char peek_buf[INP_BUFFER_SIZE]; DWORD time_to_wait; DWORD rc; HANDLE w4[2]; @@ -667,7 +668,7 @@ fhandler_tty_slave::read (void *ptr, size_t len) termios_printf ("failed to acquire input mutex after input event arrived"); break; } - if (!PeekNamedPipe (get_handle (), NULL, 0, NULL, &bytes_in_pipe, NULL)) + if (!PeekNamedPipe (get_handle (), peek_buf, sizeof(peek_buf), &bytes_in_pipe, NULL, NULL)) { termios_printf ("PeekNamedPipe failed, %E"); _raise (SIGHUP); @@ -682,6 +683,16 @@ fhandler_tty_slave::read (void *ptr, size_t len) termios_printf ("read failed, %E"); _raise (SIGHUP); } + /* MSDN states that 5th prameter can be used to determine total + number of bytes in pipe, but for some reason this number doesn't + change after successful read. So we have to peek into the pipe + again to see if input is still available */ + if (!PeekNamedPipe (get_handle (), peek_buf, 1, &bytes_in_pipe, NULL, NULL)) + { + termios_printf ("PeekNamedPipe failed, %E"); + _raise (SIGHUP); + bytes_in_pipe = 0; + } if (n) { len -= n; @@ -691,8 +702,8 @@ fhandler_tty_slave::read (void *ptr, size_t len) } } - if (readlen != bytes_in_pipe) - SetEvent (input_available_event); + if (!bytes_in_pipe) + ResetEvent (input_available_event); ReleaseMutex (input_mutex); -- cgit v1.2.3