10#include "lldb/Host/Config.h"
12#include "llvm/Config/llvm-config.h"
32 assert(result == TRUE);
37 std::vector<WSAEVENT> events;
40 int result = WSAEventSelect(fd, info.event, FD_READ | FD_ACCEPT | FD_CLOSE);
44 events.push_back(info.event);
48 DWORD result = WSAWaitForMultipleEvents(events.size(), events.data(), FALSE,
52 int result = WSAEventSelect(fd.first, WSA_INVALID_EVENT, 0);
57 if (result >= WSA_WAIT_EVENT_0 && result <= WSA_WAIT_EVENT_0 + events.size())
58 return result - WSA_WAIT_EVENT_0;
60 return llvm::createStringError(llvm::inconvertibleErrorCode(),
61 "WSAWaitForMultipleEvents failed");
67 if (!object_sp || !object_sp->IsValid()) {
68 error.SetErrorString(
"IO object is not valid.");
73 "MainLoopWindows: non-socket types unsupported on Windows");
77 WSAEVENT
event = WSACreateEvent();
78 if (event == WSA_INVALID_EVENT) {
79 error.SetErrorStringWithFormat(
"Cannot create monitoring event.");
85 .try_emplace(object_sp->GetWaitableHandle(),
FdInfo{event, callback})
89 error.SetErrorStringWithFormat(
"File descriptor %d already monitored.",
90 object_sp->GetWaitableHandle());
100 BOOL result = WSACloseEvent(it->second.event);
101 assert(result == TRUE);
109 it->second.callback(*
this);
120 llvm::Expected<size_t> signaled_event =
Poll();
122 return Status(signaled_event.takeError());
125 auto &KV = *std::next(
m_read_fds.begin(), *signaled_event);
static llvm::raw_ostream & error(Stream &strm)
std::unique_ptr< ReadHandle > ReadHandleUP
ReadHandleUP CreateReadHandle(const lldb::IOObjectSP &object_sp)
std::function< void(MainLoopBase &)> Callback
void ProcessPendingCallbacks()
llvm::Expected< size_t > Poll()
~MainLoopWindows() override
llvm::DenseMap< IOObject::WaitableHandle, FdInfo > m_read_fds
void TriggerPendingCallbacks() override
ReadHandleUP RegisterReadObject(const lldb::IOObjectSP &object_sp, const Callback &callback, Status &error) override
void UnregisterReadObject(IOObject::WaitableHandle handle) override
void ProcessReadObject(IOObject::WaitableHandle handle)
#define UNUSED_IF_ASSERT_DISABLED(x)
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::IOObject > IOObjectSP