diff options
author | Christopher Faylor <me@cgf.cx> | 2008-12-21 01:54:32 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2008-12-21 01:54:32 +0000 |
commit | 91ad1942a2ec19a654bce314c185ee1c8db8d18f (patch) | |
tree | 5385db195da267d6bf9a1a87b07697e95c83c9b2 /winsup/cygwin/pipe.cc | |
parent | 0cf888799b6874ba6a341af9dec8d4ce72f69f49 (diff) | |
download | cygnal-91ad1942a2ec19a654bce314c185ee1c8db8d18f.tar.gz cygnal-91ad1942a2ec19a654bce314c185ee1c8db8d18f.tar.bz2 cygnal-91ad1942a2ec19a654bce314c185ee1c8db8d18f.zip |
* pipe.cc (getov_result): Add parameters to facilitate better EOF checking.
(pipe_handler): Pass extra arguments to getov_result.
Diffstat (limited to 'winsup/cygwin/pipe.cc')
-rw-r--r-- | winsup/cygwin/pipe.cc | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/winsup/cygwin/pipe.cc b/winsup/cygwin/pipe.cc index 5f4717b0d..5b5a55aa6 100644 --- a/winsup/cygwin/pipe.cc +++ b/winsup/cygwin/pipe.cc @@ -39,10 +39,14 @@ struct pipesync }; inline bool -getov_result (HANDLE h, DWORD& nbytes, LPOVERLAPPED ov) +getov_result (BOOL res, bool reading, HANDLE h, DWORD& nbytes, LPOVERLAPPED ov) { - if (ov && (GetLastError () != ERROR_IO_PENDING - || !GetOverlappedResult (h, ov, &nbytes, true))) + DWORD err = GetLastError (); + if (res || (reading && ov && !res && err == ERROR_HANDLE_EOF)) + /* not an error */; + else if (!ov || (err != ERROR_IO_PENDING) + || (!GetOverlappedResult (h, ov, &nbytes, true) + && (!reading || (GetLastError () != ERROR_HANDLE_EOF)))) { __seterrno (); return false; @@ -91,13 +95,13 @@ pipe_handler (LPVOID in_ps) { ResetEvent (ov.hEvent); BOOL res = ReadFile (hread, buf, 4096, &read_bytes, rov); - if (!res && !getov_result (hread, read_bytes, rov)) + if (!getov_result (res, true, hread, read_bytes, rov)) break; if (!read_bytes) break; res = WriteFile (hwrite, buf, read_bytes, &write_bytes, wov); - if (!res && !getov_result (hwrite, write_bytes, wov)) + if (!getov_result (res, false, hwrite, write_bytes, wov)) break; if (write_bytes != read_bytes) break; |