From 041b3123ad50e89bb355ae6e2becf13a0dca2767 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 22 Aug 2021 13:19:29 +0300 Subject: [PATCH] Treat ERROR_BROKEN_PIPE as end-of-file instead of an error --- source/io/windows/eventreader.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/source/io/windows/eventreader.cpp b/source/io/windows/eventreader.cpp index 8a4c862..82d9e8c 100644 --- a/source/io/windows/eventreader.cpp +++ b/source/io/windows/eventreader.cpp @@ -18,6 +18,7 @@ struct EventReader::Private unsigned buf_avail; char *buf_next; bool pending; + bool eof; }; @@ -33,6 +34,7 @@ EventReader::EventReader(Handle &h, unsigned size): priv->buf_avail = 0; priv->buf_next = priv->buffer; priv->pending = false; + priv->eof = false; } EventReader::~EventReader() @@ -58,7 +60,9 @@ void EventReader::start() if(!ReadFile(*handle, priv->buffer, priv->buf_size, &ret, &priv->overlapped)) { unsigned err = GetLastError(); - if(err==ERROR_IO_PENDING) + if(err==ERROR_BROKEN_PIPE) + priv->eof = true; + else if(err==ERROR_IO_PENDING) priv->pending = true; else throw system_error("ReadFile"); @@ -77,7 +81,13 @@ void EventReader::wait() DWORD ret; if(!GetOverlappedResult(*handle, &priv->overlapped, &ret, true)) - throw system_error("GetOverlappedResult"); + { + DWORD err = GetLastError(); + if(err==ERROR_BROKEN_PIPE) + priv->eof = true; + else + throw system_error("GetOverlappedResult"); + } else { priv->buf_avail = ret; @@ -89,6 +99,9 @@ unsigned EventReader::read(char *buf, unsigned len) { if(!priv->buf_avail) { + if(priv->eof) + return 0; + // No data in buffer, try to get some start(); wait(); -- 2.45.2