1 #ifndef SPONGE_LIBSPONGE_EVENTLOOP_HH
2 #define SPONGE_LIBSPONGE_EVENTLOOP_HH
53 const InterestT &interest = [] {
return true; },
Specifies a condition and callback that an EventLoop should handle.
InterestT interest
A callback that returns true whenever fd should be polled.
Direction direction
Direction::In for reading from fd, Direction::Out for writing to fd.
CallbackT callback
A callback that reads or writes fd.
CallbackT cancel
A callback that is called when the rule is cancelled (e.g. on hangup)
unsigned int service_count() const
FileDescriptor fd
FileDescriptor to monitor for activity.
Waits for events on file descriptors and executes corresponding callbacks.
std::function< bool(void)> InterestT
true return indicates Rule::fd should be polled.
Result
Returned by each call to EventLoop::wait_next_event.
@ Success
At least one Rule was triggered.
@ Timeout
No rules were triggered before timeout.
@ Exit
All rules have been canceled or were uninterested; make no further calls to EventLoop::wait_next_even...
void add_rule(const FileDescriptor &fd, const Direction direction, const CallbackT &callback, const InterestT &interest=[] { return true;}, const CallbackT &cancel=[] {})
Add a rule whose callback will be called when fd is ready in the specified Direction.
Result wait_next_event(const int timeout_ms)
Calls poll(2) and then executes callback for each ready fd.
std::function< void(void)> CallbackT
Callback for ready Rule::fd.
std::list< Rule > _rules
All rules that have been added and not canceled.
Direction
Indicates interest in reading (In) or writing (Out) a polled fd.
@ Out
Callback will be triggered when Rule::fd is writable.
@ In
Callback will be triggered when Rule::fd is readable.
A reference-counted handle to a file descriptor.