33#error "epoll is not available on windows"
86 return epoll_ctl(
_epoll, EPOLL_CTL_MOD, item.data.fd, &item);
97 return epoll_ctl(
_epoll, EPOLL_CTL_ADD, item.data.fd, &item);
108 return epoll_ctl(
_epoll, EPOLL_CTL_DEL, item.data.fd,
nullptr);
124template <std::
size_t _MAX_EVENTS = 4096>
126 epoll_event _epvts[_MAX_EVENTS];
136 :
Proxy(epoll_create(_MAX_EVENTS)) {
138 throw std::runtime_error(
"failed to init epoll::Poller");
168 template <
typename _Func>
170 wait(_Func
const &func,
int const timeout = 0) {
171 const int ret = epoll_wait(
_epoll, _epvts, _MAX_EVENTS, timeout);
173 std::cerr <<
"epoll::Poller polling has failed " << std::endl;
176 for (
int i = 0; i < ret; ++i) {
Branch prediction hint utilities for performance optimization.
Poller()
Constructor.
Definition epoll.h:135
Poller(Poller const &)=delete
Copy constructor (deleted)
void wait(_Func const &func, int const timeout=0)
Wait for events and process them.
Definition epoll.h:170
~Poller()
Destructor.
Definition epoll.h:153
epoll_event item_type
Type alias for epoll event item.
Definition epoll.h:71
Proxy()=default
Default constructor.
int ctl(item_type &item) const
Modify an existing file descriptor in the epoll set.
Definition epoll.h:85
int _epoll
The epoll file descriptor.
Definition epoll.h:52
int add(item_type &item) const
Add a new file descriptor to the epoll set.
Definition epoll.h:96
Proxy(const int epoll)
Constructor.
Definition epoll.h:64
int remove(item_type const &item)
Remove a file descriptor from the epoll set.
Definition epoll.h:107
Proxy(Proxy const &)=default
Copy constructor.
bool unlikely(bool expr)
Hint for branch prediction when a condition is expected to be false.
Definition branch_hints.h:76