diff options
author | Christopher Faylor <me@cgf.cx> | 2012-05-16 05:56:41 +0400 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2012-05-16 05:56:41 +0400 |
commit | bd8afa5eb160b56715b805befe850a5ba2131d28 (patch) | |
tree | 660c70336eea7bae533e991684bb76b0205f8131 /winsup/cygwin/fhandler_tty.cc | |
parent | c846faf01a34f9510ac234499e4868845e12e029 (diff) |
* DevNotes: Add entry cgf-000008.
* fhandler_tty.cc (bytes_available): Simplify by returning the number of bytes
available in the message unless that is zero.
Diffstat (limited to 'winsup/cygwin/fhandler_tty.cc')
-rw-r--r-- | winsup/cygwin/fhandler_tty.cc | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 1428a064e..38a0571cb 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -53,17 +53,20 @@ fhandler_pty_slave::get_unit () bool bytes_available (DWORD& n, HANDLE h) { - char buf[INP_BUFFER_SIZE]; - /* Apparently need to pass in a dummy buffer to read a real "record" from - the pipe. So buf is used and then discarded just so we can see how many - bytes will be read by the next ReadFile(). */ - bool succeeded = PeekNamedPipe (h, buf, sizeof (buf), &n, NULL, NULL); - if (!succeeded) + DWORD navail, nleft; + navail = nleft = 0; + bool succeeded = PeekNamedPipe (h, NULL, 0, NULL, &navail, &nleft); + if (succeeded) + /* nleft should always be the right choice unless something has written 0 + bytes to the pipe. In that pathological case we return the actual number + of bytes available in the pipe. See cgf-000008 for more details. */ + n = nleft ?: navail; + else { termios_printf ("PeekNamedPipe(%p) failed, %E", h); n = 0; } - debug_only_printf ("%u bytes available", n); + debug_only_printf ("n %u, nleft %u, navail %u"); return succeeded; } |