Index: fhandler.h =================================================================== RCS file: /cvs/src/src/winsup/cygwin/fhandler.h,v retrieving revision 1.48 diff -u -p -2 -r1.48 fhandler.h --- fhandler.h 2001/03/12 21:27:42 1.48 +++ fhandler.h 2001/03/18 13:49:37 @@ -762,4 +762,6 @@ public: off_t lseek (off_t, int) { return 0; } + virtual select_record *select_read (select_record *s); + int ready_for_read (int fd, DWORD howlong, int ignra); }; Index: fhandler_termios.cc =================================================================== RCS file: /cvs/src/src/winsup/cygwin/fhandler_termios.cc,v retrieving revision 1.16 diff -u -p -2 -r1.16 fhandler_termios.cc --- fhandler_termios.cc 2001/03/17 02:15:33 1.16 +++ fhandler_termios.cc 2001/03/18 13:49:37 @@ -210,4 +210,5 @@ fhandler_termios::line_edit (const char termios_printf ("got interrupt %d, sending signal %d", c, sig); + eat_readahead (-1); kill_pgrp (tc->getpgid (), sig); tc->ti.c_lflag &= ~FLUSHO; Index: fhandler_tty.cc =================================================================== RCS file: /cvs/src/src/winsup/cygwin/fhandler_tty.cc,v retrieving revision 1.28 diff -u -p -2 -r1.28 fhandler_tty.cc --- fhandler_tty.cc 2001/03/17 01:45:40 1.28 +++ fhandler_tty.cc 2001/03/18 13:49:38 @@ -615,4 +615,5 @@ fhandler_tty_slave::read (void *ptr, siz DWORD bytes_in_pipe; char buf[INP_BUFFER_SIZE]; + char peek_buf[INP_BUFFER_SIZE]; DWORD time_to_wait; DWORD rc; @@ -668,5 +669,5 @@ fhandler_tty_slave::read (void *ptr, siz 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"); @@ -683,4 +684,14 @@ fhandler_tty_slave::read (void *ptr, siz _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 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) { @@ -692,6 +703,6 @@ fhandler_tty_slave::read (void *ptr, siz } - if (readlen != bytes_in_pipe) - SetEvent (input_available_event); + if (!bytes_in_pipe) + ResetEvent (input_available_event); ReleaseMutex (input_mutex); Index: select.cc =================================================================== RCS file: /cvs/src/src/winsup/cygwin/select.cc,v retrieving revision 1.32 diff -u -p -2 -r1.32 select.cc --- select.cc 2001/03/18 03:34:05 1.32 +++ select.cc 2001/03/18 13:49:38 @@ -744,4 +744,51 @@ fhandler_tty_common::select_except (sele } +static int +verify_tty_slave (select_record *me, fd_set *readfds, fd_set *writefds, + fd_set *exceptfds) +{ + if (WaitForSingleObject (me->h, 0) == WAIT_OBJECT_0) + me->read_ready = 1; + return set_bits (me, readfds, writefds, exceptfds); +} + +select_record * +fhandler_tty_slave::select_read (select_record *s) +{ + if (!s) + s = new select_record; + s->h = input_available_event; + s->startup = no_startup; + s->poll = poll_pipe; + s->verify = verify_tty_slave; + s->read_selected = TRUE; + s->cleanup = NULL; + return s; +} + +int +fhandler_tty_slave::ready_for_read (int fd, DWORD howlong, int ignra) +{ + HANDLE w4[2]; + if (!ignra && get_readahead_valid ()) + { + select_printf ("readahead"); + return 1; + } + w4[0] = signal_arrived; + w4[1] = input_available_event; + switch (WaitForMultipleObjects (2, w4, FALSE, howlong)) + { + case WAIT_OBJECT_0 + 1: + return 1; + case WAIT_FAILED: + select_printf ( "wait failed %E" ); + case WAIT_OBJECT_0: + case WAIT_TIMEOUT: + default: + return 0; + } +} + select_record * fhandler_dev_null::select_read (select_record *s) Index: tty.cc =================================================================== RCS file: /cvs/src/src/winsup/cygwin/tty.cc,v retrieving revision 1.15 diff -u -p -2 -r1.15 tty.cc --- tty.cc 2001/03/18 03:34:05 1.15 +++ tty.cc 2001/03/18 13:49:38 @@ -326,5 +326,5 @@ tty::init (void) HANDLE -tty::get_event (const char *fmt, BOOL inherit) +tty::get_event (const char *fmt, BOOL inherit, BOOL manual_reset) { HANDLE hev; @@ -332,5 +332,5 @@ tty::get_event (const char *fmt, BOOL in __small_sprintf (buf, fmt, ntty); - if (!(hev = CreateEvent (inherit ? &sec_all : &sec_all_nih, FALSE, FALSE, buf))) + if (!(hev = CreateEvent (inherit ? &sec_all : &sec_all_nih, manual_reset, FALSE, buf))) { termios_printf ("couldn't create %s", buf); @@ -409,5 +409,5 @@ tty::common_init (fhandler_pty_master *p } - if (!(ptym->input_available_event = get_event (INPUT_AVAILABLE_EVENT, FALSE))) + if (!(ptym->input_available_event = get_event (INPUT_AVAILABLE_EVENT, FALSE, TRUE))) return FALSE; Index: tty.h =================================================================== RCS file: /cvs/src/src/winsup/cygwin/tty.h,v retrieving revision 1.3 diff -u -p -2 -r1.3 tty.h --- tty.h 2001/03/04 15:34:25 1.3 +++ tty.h 2001/03/18 13:49:38 @@ -87,5 +87,5 @@ class fhandler_pty_master; class tty: public tty_min { - HANDLE get_event (const char *fmt, BOOL inherit); + HANDLE get_event (const char *fmt, BOOL inherit, BOOL manual_reset = FALSE); public: HWND hwnd; /* Console window handle tty belongs to */