diff --git a/init/epoll.cpp b/init/epoll.cpp index 4bca09e6d..94dd55350 100644 --- a/init/epoll.cpp +++ b/init/epoll.cpp @@ -16,6 +16,7 @@ #include "epoll.h" +#include #include #include @@ -37,13 +38,16 @@ Result Epoll::Open() { return Success(); } -Result Epoll::RegisterHandler(int fd, std::function handler) { +Result Epoll::RegisterHandler(int fd, std::function 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(&it->second); diff --git a/init/epoll.h b/init/epoll.h index 85a791c60..9789bef58 100644 --- a/init/epoll.h +++ b/init/epoll.h @@ -17,6 +17,9 @@ #ifndef _INIT_EPOLL_H #define _INIT_EPOLL_H +#include +#include + #include #include #include @@ -34,7 +37,8 @@ class Epoll { Epoll(); Result Open(); - Result RegisterHandler(int fd, std::function handler); + Result RegisterHandler(int fd, std::function handler, + uint32_t events = EPOLLIN); Result UnregisterHandler(int fd); Result Wait(std::optional timeout);