* pipe.cc (getov_result): Add parameters to facilitate better EOF checking.

(pipe_handler): Pass extra arguments to getov_result.
This commit is contained in:
Christopher Faylor 2008-12-21 01:54:32 +00:00
parent 0cf888799b
commit 91ad1942a2
2 changed files with 15 additions and 5 deletions

View File

@ -1,3 +1,9 @@
2008-12-20 Christopher Faylor <me+cygwin@cgf.cx>
* pipe.cc (getov_result): Add parameters to facilitate better EOF
checking.
(pipe_handler): Pass extra arguments to getov_result.
2008-12-20 Christopher Faylor <me+cygwin@cgf.cx> 2008-12-20 Christopher Faylor <me+cygwin@cgf.cx>
* fhandler.cc (fhandler_base::wait_overlapped): Reorganize to eliminate * fhandler.cc (fhandler_base::wait_overlapped): Reorganize to eliminate

View File

@ -39,10 +39,14 @@ struct pipesync
}; };
inline bool 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 DWORD err = GetLastError ();
|| !GetOverlappedResult (h, ov, &nbytes, true))) 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 (); __seterrno ();
return false; return false;
@ -91,13 +95,13 @@ pipe_handler (LPVOID in_ps)
{ {
ResetEvent (ov.hEvent); ResetEvent (ov.hEvent);
BOOL res = ReadFile (hread, buf, 4096, &read_bytes, rov); 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; break;
if (!read_bytes) if (!read_bytes)
break; break;
res = WriteFile (hwrite, buf, read_bytes, &write_bytes, wov); 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; break;
if (write_bytes != read_bytes) if (write_bytes != read_bytes)
break; break;