![]() |
dfx 0.1.0
Linux-based dynamic dataflow executor
|
epoll-based implementation of Poller. More...
#include <dfx-fdwatch/EPollPoller.hpp>
Public Member Functions | |
| EPollPoller () | |
| Constructs the poller and initializes underlying kernel resources. | |
| DFX_DISABLE_COPY_AND_MOVE (EPollPoller) | |
| Non-copyable, non-movable. | |
| void | registerFd (Utils::BorrowedFd fd, EventInterests events, FdCallback cb) override |
| Registers a file descriptor with the poller. | |
| void | deregisterFd (Utils::BorrowedFd fd) noexcept override |
| Deregisters a file descriptor from the poller. | |
| void | updateFdEvents (Utils::BorrowedFd fd, EventInterests events) override |
| Update the list of event that this fd is attached to. | |
| void | deferCall (Callback cb) override |
| Defer the call to the callback to the next time the event loop is reached. | |
| void | exec () |
| Runs the event loop until stopping is requested. | |
| void | exec (std::stop_token stopToken) |
| Runs the event loop until stopToken.stop_requested() returns true. | |
| void | requestStop () noexcept |
| Requests the event loop to stop (non-blocking). | |
| void | stop () |
| Stops the event loop. | |
| void | wake () |
| Wakes the event loop. Useful when a stop has been requested while the loop is blocked in epoll_wait(). | |
| bool | isRunning () const noexcept |
| Returns whether the event loop is currently running. | |
| Public Member Functions inherited from dfx::FdWatch::Poller | |
| virtual | ~Poller ()=default |
| Virtual destructor for interface. | |
epoll-based implementation of Poller.
EPollPoller is the concrete event loop used by dfx to monitor file descriptors and dispatch callbacks when I/O readiness events occur.
It implements the Poller interface:
The main loop is driven by exec(). It blocks waiting for events and invokes the registered callbacks when events are received.
Internally, it uses an epoll instance FD and a wakeup FD (commonly eventfd) to interrupt epoll_wait() when work is deferred or when stopping is requested.
| dfx::FdWatch::EPollPoller::EPollPoller | ( | ) |
Constructs the poller and initializes underlying kernel resources.
Creates the epoll instance and the wakeup FD used by wake() and deferCall().
|
overridevirtual |
Defer the call to the callback to the next time the event loop is reached.
The callback will be invoked as soon as all currently pending event in the event loop have been processed.
| cb | Callback to be invoked later. |
Implements dfx::FdWatch::Poller.
|
overridevirtualnoexcept |
Deregisters a file descriptor from the poller.
After this call, the poller will no longer monitor the FD and no callbacks will be triggered for it.
| fd | Borrowed file descriptor to remove. |
Implements dfx::FdWatch::Poller.
| dfx::FdWatch::EPollPoller::DFX_DISABLE_COPY_AND_MOVE | ( | EPollPoller | ) |
Non-copyable, non-movable.
The poller owns kernel resources and maintains registrations that cannot be safely duplicated or transferred.
| void dfx::FdWatch::EPollPoller::exec | ( | ) |
Runs the event loop until stopping is requested.
This call blocks, processing registered FD events and executing deferred callbacks until requestStop() or stop() is used.
| void dfx::FdWatch::EPollPoller::exec | ( | std::stop_token | stopToken | ) |
Runs the event loop until stopToken.stop_requested() returns true.
This call blocks, processing registered FD events and executing deferred callbacks until the associated stop source request a stop.
|
inlinenoexcept |
Returns whether the event loop is currently running.
|
overridevirtual |
Registers a file descriptor with the poller.
Once registered, the poller will monitor fd for the specified events and invoke cb when they occur.
| fd | Borrowed file descriptor to monitor. |
| events | Events of interest. |
| cb | Callback invoked when events occur. |
fd must refer to a valid, open file descriptor. Implements dfx::FdWatch::Poller.
|
noexcept |
Requests the event loop to stop (non-blocking).
This function only works for the case where exec has been called without a stop_token parameter.
| void dfx::FdWatch::EPollPoller::stop | ( | ) |
|
overridevirtual |
Update the list of event that this fd is attached to.
| fd | Borrowed file descriptor to update. |
| events | The new list of event to listen for. |
Implements dfx::FdWatch::Poller.
| void dfx::FdWatch::EPollPoller::wake | ( | ) |
Wakes the event loop. Useful when a stop has been requested while the loop is blocked in epoll_wait().
This function will work regardless of which exec function is used.