Migrate GuestTelemetryLogger to MultiHandleWait IO infrastructure (#40730)

Replace the manual for(;;) InterruptableRead loop with the
io::MultiHandleWait/ReadHandle/EventHandle model already used by the
console relay, so guest telemetry reads share the unified overlapped-IO
wait path.

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-06-17 18:55:10 -07:00
1 parent 8bc3684ec9
commit 28447f5f06
1 file changed
+20 -15
@@ -61,23 +61,28 @@ void GuestTelemetryLogger::Start(const wil::unique_event& ExitEvent)
const std::vector<HANDLE> exitEvents = {m_threadExit.get(), ExitEvent.get()};
wsl::windows::common::helpers::ConnectPipe(Pipe.get(), INFINITE, exitEvents);
std::vector<gsl::byte> buffer(LX_RELAY_BUFFER_SIZE);
OVERLAPPED overlapped = {};
const wil::unique_event overlappedEvent(wil::EventOptions::ManualReset);
overlapped.hEvent = overlappedEvent.get();
for (;;)
{
overlappedEvent.ResetEvent();
const auto bytesRead =
wsl::windows::common::relay::InterruptableRead(Pipe.get(), gsl::make_span(buffer), exitEvents, &overlapped);
namespace io = wsl::windows::common::io;
io::MultiHandleWait ioWait;
ioWait.AddHandle(
std::make_unique<io::ReadHandle>(
io::HandleWrapper{Pipe.get()},
[this](const gsl::span<char>& buffer) {
if (!buffer.empty())
{
ProcessInput(std::string_view{buffer.data(), static_cast<size_t>(buffer.size())});
}
}),
io::MultiHandleWait::IgnoreErrors);
if (bytesRead == 0)
{
break;
}
ioWait.AddHandle(
std::make_unique<io::EventHandle>(io::HandleWrapper{m_threadExit.get()}),
io::MultiHandleWait::CancelOnCompleted | io::MultiHandleWait::NeedNotComplete);
ProcessInput(std::string_view{reinterpret_cast<const char*>(buffer.data()), bytesRead});
}
ioWait.AddHandle(
std::make_unique<io::EventHandle>(io::HandleWrapper{ExitEvent.get()}),
io::MultiHandleWait::CancelOnCompleted | io::MultiHandleWait::NeedNotComplete);
ioWait.Run(std::nullopt);
}
CATCH_LOG()
});