From 31d2bedc585420092eb53895c5f5646651f13215 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Sun, 23 Oct 2011 19:01:47 +0000 Subject: [PATCH] * fhandler_tty.cc (fhandler_pty_slave::read): Use consistent way for testing ReadFile return. * pipe.cc (fhandler_pipe::create_selectable): Open the write side of the pipe in message-mode to force writing as "chunks". Explain why. --- winsup/cygwin/ChangeLog | 7 +++++++ winsup/cygwin/fhandler_tty.cc | 2 +- winsup/cygwin/pipe.cc | 10 ++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 19ee92fd3..33b7c6c38 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,10 @@ +2011-10-23 Christopher Faylor + + * fhandler_tty.cc (fhandler_pty_slave::read): Use consistent way for + testing ReadFile return. + * pipe.cc (fhandler_pipe::create_selectable): Open the write side of + the pipe in message-mode to force writing as "chunks". Explain why. + 2011-10-23 Christopher Faylor * path.cc (path_conv::get_nt_native_path): Avoid dereferencing path diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index f3a9a5f34..b019db046 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -812,7 +812,7 @@ fhandler_pty_slave::read (void *ptr, size_t& len) if (readlen) { termios_printf ("reading %d bytes (vtime %d)", readlen, vtime); - if (ReadFile (get_handle (), buf, readlen, &n, NULL) == FALSE) + if (!ReadFile (get_handle (), buf, readlen, &n, NULL)) { termios_printf ("read failed, %E"); raise (SIGHUP); diff --git a/winsup/cygwin/pipe.cc b/winsup/cygwin/pipe.cc index aa56cf531..99c79121e 100644 --- a/winsup/cygwin/pipe.cc +++ b/winsup/cygwin/pipe.cc @@ -238,9 +238,15 @@ fhandler_pipe::create_selectable (LPSECURITY_ATTRIBUTES sa_ptr, HANDLE& r, It's important to only allow a single instance, to ensure that the pipe was not created earlier by some other process, even if the pid has been reused. We avoid FILE_FLAG_FIRST_PIPE_INSTANCE - because that is only available for Win2k SP2 and WinXP. */ + because that is only available for Win2k SP2 and WinXP. + + Note that the write side of the pipe is opened as PIPE_TYPE_MESSAGE. + This *seems* to more closely mimic Linux pipe behavior and is + definitely required for pty handling since fhandler_pty_master + writes to the pipe in chunks, terminated by newline when CANON mode + is specified. */ r = CreateNamedPipe (pipename, PIPE_ACCESS_INBOUND | overlapped, - PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 1, psize, + PIPE_TYPE_MESSAGE | PIPE_READMODE_BYTE, 1, psize, psize, NMPWAIT_USE_DEFAULT_WAIT, sa_ptr); if (r != INVALID_HANDLE_VALUE)