Loading init/epoll.cpp +6 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ #include "epoll.h" #include <stdint.h> #include <sys/epoll.h> #include <chrono> Loading @@ -37,13 +38,16 @@ Result<Success> Epoll::Open() { return Success(); } Result<Success> Epoll::RegisterHandler(int fd, std::function<void()> handler) { Result<Success> Epoll::RegisterHandler(int fd, std::function<void()> handler, uint32_t events) { if (!events) { return Error() << "Must specify events"; } auto [it, inserted] = epoll_handlers_.emplace(fd, std::move(handler)); if (!inserted) { return Error() << "Cannot specify two epoll handlers for a given FD"; } epoll_event ev; ev.events = EPOLLIN; ev.events = events; // std::map's iterators do not get invalidated until erased, so we use the // pointer to the std::function in the map directly for epoll_ctl. ev.data.ptr = reinterpret_cast<void*>(&it->second); Loading init/epoll.h +5 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,9 @@ #ifndef _INIT_EPOLL_H #define _INIT_EPOLL_H #include <stdint.h> #include <sys/epoll.h> #include <chrono> #include <functional> #include <map> Loading @@ -34,7 +37,8 @@ class Epoll { Epoll(); Result<Success> Open(); Result<Success> RegisterHandler(int fd, std::function<void()> handler); Result<Success> RegisterHandler(int fd, std::function<void()> handler, uint32_t events = EPOLLIN); Result<Success> UnregisterHandler(int fd); Result<Success> Wait(std::optional<std::chrono::milliseconds> timeout); Loading Loading
init/epoll.cpp +6 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ #include "epoll.h" #include <stdint.h> #include <sys/epoll.h> #include <chrono> Loading @@ -37,13 +38,16 @@ Result<Success> Epoll::Open() { return Success(); } Result<Success> Epoll::RegisterHandler(int fd, std::function<void()> handler) { Result<Success> Epoll::RegisterHandler(int fd, std::function<void()> handler, uint32_t events) { if (!events) { return Error() << "Must specify events"; } auto [it, inserted] = epoll_handlers_.emplace(fd, std::move(handler)); if (!inserted) { return Error() << "Cannot specify two epoll handlers for a given FD"; } epoll_event ev; ev.events = EPOLLIN; ev.events = events; // std::map's iterators do not get invalidated until erased, so we use the // pointer to the std::function in the map directly for epoll_ctl. ev.data.ptr = reinterpret_cast<void*>(&it->second); Loading
init/epoll.h +5 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,9 @@ #ifndef _INIT_EPOLL_H #define _INIT_EPOLL_H #include <stdint.h> #include <sys/epoll.h> #include <chrono> #include <functional> #include <map> Loading @@ -34,7 +37,8 @@ class Epoll { Epoll(); Result<Success> Open(); Result<Success> RegisterHandler(int fd, std::function<void()> handler); Result<Success> RegisterHandler(int fd, std::function<void()> handler, uint32_t events = EPOLLIN); Result<Success> UnregisterHandler(int fd); Result<Success> Wait(std::optional<std::chrono::milliseconds> timeout); Loading