Index: util/file/file_io_win.cc |
diff --git a/util/file/file_io_win.cc b/util/file/file_io_win.cc |
index 861f15acc64e2243c2b5d024bc68f7b947ff15e4..adbe7a99efaa15498877220d67c38c40860f4170 100644 |
--- a/util/file/file_io_win.cc |
+++ b/util/file/file_io_win.cc |
@@ -44,10 +44,16 @@ ssize_t ReadFile(FileHandle file, void* buffer, size_t size) { |
while (size_dword > 0) { |
DWORD bytes_read; |
BOOL success = ::ReadFile(file, buffer_c, size_dword, &bytes_read, nullptr); |
- if (!success && GetLastError() != ERROR_MORE_DATA) { |
- return -1; |
- } else if (success && bytes_read == 0 && |
- GetFileType(file) != FILE_TYPE_PIPE) { |
+ if (!success) { |
+ if (GetLastError() == ERROR_BROKEN_PIPE) { |
+ // When reading a pipe and the write handle has been closed, ReadFile |
+ // fails with ERROR_BROKEN_PIPE, but only once all pending data has been |
+ // read. |
+ break; |
+ } else if (GetLastError() != ERROR_MORE_DATA) { |
+ return -1; |
+ } |
+ } else if (bytes_read == 0 && GetFileType(file) != FILE_TYPE_PIPE) { |
// Zero bytes read for a file indicates reaching EOF. Zero bytes read from |
// a pipe indicates only that there was a zero byte WriteFile issued on |
// the other end, so continue reading. |