summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/fhandler_tty.cc
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2012-05-16 01:56:41 +0000
committerChristopher Faylor <me@cgf.cx>2012-05-16 01:56:41 +0000
commitbd8afa5eb160b56715b805befe850a5ba2131d28 (patch)
tree660c70336eea7bae533e991684bb76b0205f8131 /winsup/cygwin/fhandler_tty.cc
parentc846faf01a34f9510ac234499e4868845e12e029 (diff)
downloadcygnal-bd8afa5eb160b56715b805befe850a5ba2131d28.tar.gz
cygnal-bd8afa5eb160b56715b805befe850a5ba2131d28.tar.bz2
cygnal-bd8afa5eb160b56715b805befe850a5ba2131d28.zip
* 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.cc17
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;
}