diff options
Diffstat (limited to 'winsup/cygwin/fhandler_tty.cc')
-rw-r--r-- | winsup/cygwin/fhandler_tty.cc | 17 |
1 files changed, 14 insertions, 3 deletions
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); |