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