mirror of
https://github.com/aphrody-labs/WSL.git
synced 2026-10-17 12:45:55 +00:00
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:
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()
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user