Lely core libraries  2.2.5
poll.hpp
Go to the documentation of this file.
1 
24 #ifndef LELY_EV_POLL_HPP_
25 #define LELY_EV_POLL_HPP_
26 
27 #include <lely/ev/poll.h>
28 #include <lely/util/error.hpp>
29 
30 namespace lely {
31 namespace ev {
32 
36 class Poll {
37  public:
38  explicit Poll(ev_poll_t* poll) noexcept : poll_(poll) {}
39 
40  operator ev_poll_t*() const noexcept { return poll_; }
41 
43  void*
44  self() const noexcept {
45  return ev_poll_self(*this);
46  }
47 
49  void
50  wait(int timeout) {
51  if (ev_poll_wait(*this, timeout) == -1) util::throw_errc("wait");
52  }
53 
55  void
56  kill(void* thr) {
57  if (ev_poll_kill(*this, thr) == -1) util::throw_errc("kill");
58  }
59 
60  protected:
61  ev_poll_t* poll_{nullptr};
62 };
63 
64 } // namespace ev
65 } // namespace lely
66 
67 #endif // !LELY_EV_POLL_HPP_
The abstract polling interface.
Definition: poll.hpp:36
void kill(void *thr)
Definition: poll.hpp:56
void wait(int timeout)
Definition: poll.hpp:50
This header file is part of the utilities library; it contains C++ convenience functions for creating...
This header file is part of the event library; it contains the abstract polling interface.
void * ev_poll_self(const ev_poll_t *poll)
Returns the identifier of the calling thread.
Definition: poll.h:69
const struct ev_poll_vtbl *const ev_poll_t
The abstract polling interface.
Definition: poll.h:32
int ev_poll_kill(ev_poll_t *poll, void *thr)
Interrupts a polling wait on the specified thread.
Definition: poll.h:81
int ev_poll_wait(ev_poll_t *poll, int timeout)
Waits for at most timeout milliseconds while polling for new events.
Definition: poll.h:75