Skip to content

Commit

Permalink
frontend: Ensure to read till newline
Browse files Browse the repository at this point in the history
  • Loading branch information
magicant committed Jul 17, 2024
1 parent 8f0a570 commit 3c9c179
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions frontend/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,29 @@ namespace {
}

std::string receive_from_backend() {
std::string line;
std::array<char, 8192> buffer{};
DWORD read_count = 0;
if (!ReadFile(
pipe_from_backend,
buffer.data(),
static_cast<DWORD>(buffer.size()),
&read_count,
NULL)) {
read_count = 0;
}
for (;;) {
DWORD read_count = 0;
if (!ReadFile(
pipe_from_backend,
buffer.data(),
static_cast<DWORD>(buffer.size()),
&read_count,
NULL))
{
line.clear();
break;
}

return std::string(
buffer.data(),
static_cast<std::size_t>(read_count));
std::string_view fragment(
buffer.data(), static_cast<std::size_t>(read_count));
line.append(fragment);
if (fragment.find('\n') != std::string_view::npos) {
break;
}
}
return line;
}
}

Expand Down

0 comments on commit 3c9c179

Please sign in to comment.