Commit 72f37e3d authored by Artur Wojcik's avatar Artur Wojcik
Browse files

fix broken pipe

parent b9eb03e7
...@@ -162,19 +162,14 @@ class pipe ...@@ -162,19 +162,14 @@ class pipe
return result; return result;
} }
std::optional<std::pair<bool, DWORD>> read(LPVOID buffer, DWORD length) const std::pair<bool, DWORD> read(LPVOID buffer, DWORD length) const
{ {
DWORD bytes_read; DWORD bytes_read;
if(ReadFile(m_read, buffer, length, &bytes_read, nullptr) == FALSE) if(ReadFile(m_read, buffer, length, &bytes_read, nullptr) == FALSE and GetLastError() == ERROR_MORE_DATA)
{ {
DWORD error{GetLastError()}; return {true, bytes_read};
if(error != ERROR_MORE_DATA)
{
return std::nullopt;
}
return {{true, bytes_read}};
} }
return {{false, bytes_read}}; return {false, bytes_read};
} }
HANDLE get_read_handle() const { return m_read; } HANDLE get_read_handle() const { return m_read; }
...@@ -277,15 +272,12 @@ int exec(const std::pair<std::string, std::string>& cmd) ...@@ -277,15 +272,12 @@ int exec(const std::pair<std::string, std::string>& cmd)
: exec(cmd, [&](const pipe<direction::input>&, const pipe<direction::output>& out) { : exec(cmd, [&](const pipe<direction::input>&, const pipe<direction::output>& out) {
for(;;) for(;;)
{ {
if(auto result = out.read(buffer, MIGRAPHX_PROCESS_BUFSIZE)) auto [more_data, bytes_read] = out.read(buffer, MIGRAPHX_PROCESS_BUFSIZE);
{ if(not more_data or bytes_read == 0)
auto& [more_data, bytes_read] = *result; break;
if(not more_data or bytes_read == 0) DWORD written;
break; if(WriteFile(std_out, buffer, bytes_read, &written, nullptr) == FALSE)
DWORD written; break;
if(WriteFile(std_out, buffer, bytes_read, &written, nullptr) == FALSE)
break;
}
} }
}); });
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment