10#include "lldb/Host/Config.h"
12#include "llvm/Config/llvm-config.h"
24static DWORD
ToTimeout(std::optional<MainLoopWindows::TimePoint> point) {
25 using namespace std::chrono;
30 nanoseconds dur = (std::max)(*point - steady_clock::now(), nanoseconds(0));
31 return ceil<milliseconds>(dur).count();
42 assert(result == TRUE);
47 std::vector<WSAEVENT> events;
50 int result = WSAEventSelect(fd, info.event, FD_READ | FD_ACCEPT | FD_CLOSE);
54 events.push_back(info.event);
59 WSAWaitForMultipleEvents(events.size(), events.data(), FALSE,
63 int result = WSAEventSelect(fd.first, WSA_INVALID_EVENT, 0);
68 if (result >= WSA_WAIT_EVENT_0 && result < WSA_WAIT_EVENT_0 + events.size())
69 return result - WSA_WAIT_EVENT_0;
72 if (result == WSA_WAIT_TIMEOUT)
73 return events.size() - 1;
75 return llvm::createStringError(llvm::inconvertibleErrorCode(),
76 "WSAWaitForMultipleEvents failed");
82 if (!object_sp || !object_sp->IsValid()) {
88 "MainLoopWindows: non-socket types unsupported on Windows");
92 WSAEVENT
event = WSACreateEvent();
93 if (event == WSA_INVALID_EVENT) {
101 .try_emplace(object_sp->GetWaitableHandle(),
FdInfo{event, callback})
104 WSACloseEvent(event);
106 "File descriptor %d already monitored.",
107 object_sp->GetWaitableHandle());
117 BOOL result = WSACloseEvent(it->second.event);
118 assert(result == TRUE);
126 it->second.callback(*
this);
135 llvm::Expected<size_t> signaled_event =
Poll();
140 auto &KV = *std::next(
m_read_fds.begin(), *signaled_event);
141 WSAResetEvent(KV.second.event);
static llvm::raw_ostream & error(Stream &strm)
static DWORD ToTimeout(std::optional< MainLoopWindows::TimePoint > point)
std::unique_ptr< ReadHandle > ReadHandleUP
std::optional< TimePoint > GetNextWakeupTime()
ReadHandleUP CreateReadHandle(const lldb::IOObjectSP &object_sp)
std::function< void(MainLoopBase &)> Callback
void Interrupt() override
llvm::Expected< size_t > Poll()
~MainLoopWindows() override
llvm::DenseMap< IOObject::WaitableHandle, FdInfo > m_read_fds
ReadHandleUP RegisterReadObject(const lldb::IOObjectSP &object_sp, const Callback &callback, Status &error) override
void UnregisterReadObject(IOObject::WaitableHandle handle) override
void ProcessReadObject(IOObject::WaitableHandle handle)
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
static Status FromErrorString(const char *str)
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
#define UNUSED_IF_ASSERT_DISABLED(x)
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::IOObject > IOObjectSP