dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
dfx::FdWatch::EPollPoller Class Reference

epoll-based implementation of Poller. More...

#include <dfx-fdwatch/EPollPoller.hpp>

Inheritance diagram for dfx::FdWatch::EPollPoller:
[legend]
Collaboration diagram for dfx::FdWatch::EPollPoller:
[legend]

Public Member Functions

 EPollPoller ()
 Constructs the poller and initializes underlying kernel resources.
 DISABLE_COPY_AND_MOVE (EPollPoller)
 Non-copyable, non-movable.
 ~EPollPoller ()
 Destroys the poller and releases kernel resources. The poller must not be running while being destroyed.
void registerFd (BorrowedFd fd, EventInterests events, FdCallback cb) override
 Registers a file descriptor with the poller.
void deregisterFd (BorrowedFd fd) noexcept override
 Deregisters a file descriptor from the poller.
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 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.

Detailed Description

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.

See also
Poller

Constructor & Destructor Documentation

◆ EPollPoller()

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().

◆ ~EPollPoller()

dfx::FdWatch::EPollPoller::~EPollPoller ( )

Destroys the poller and releases kernel resources. The poller must not be running while being destroyed.

Member Function Documentation

◆ deferCall()

void dfx::FdWatch::EPollPoller::deferCall ( Callback cb)
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.

Parameters
cbCallback to be invoked later.

Implements dfx::FdWatch::Poller.

◆ deregisterFd()

void dfx::FdWatch::EPollPoller::deregisterFd ( BorrowedFd fd)
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.

Parameters
fdBorrowed file descriptor to remove.
Note
Deregistering an FD that is not registered is allowed

Implements dfx::FdWatch::Poller.

◆ DISABLE_COPY_AND_MOVE()

dfx::FdWatch::EPollPoller::DISABLE_COPY_AND_MOVE ( EPollPoller )

Non-copyable, non-movable.

The poller owns kernel resources and maintains registrations that cannot be safely duplicated or transferred.

◆ exec()

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.

Note
This function is expected to be called from a single thread. Also this function cannot be called recursively.

◆ isRunning()

bool dfx::FdWatch::EPollPoller::isRunning ( ) const
inlinenoexcept

Returns whether the event loop is currently running.

◆ registerFd()

void dfx::FdWatch::EPollPoller::registerFd ( BorrowedFd fd,
EventInterests events,
FdCallback cb )
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.

Parameters
fdBorrowed file descriptor to monitor.
eventsEvents of interest.
cbCallback invoked when events occur.
Precondition
fd must refer to a valid, open file descriptor.
Note
Registering the same FD more than once is a no-op. If you want to change the events monitored of the callback, then the FD must be deregistered first

Implements dfx::FdWatch::Poller.

◆ requestStop()

void dfx::FdWatch::EPollPoller::requestStop ( )
noexcept

Requests the event loop to stop (non-blocking).

◆ stop()

void dfx::FdWatch::EPollPoller::stop ( )

Stops the event loop.

Perform the requestStop and wake operation in sequence

◆ wake()

void dfx::FdWatch::EPollPoller::wake ( )

Wakes the event loop. Useful when a stop has been requested while the loop is blocked in epoll_wait().


The documentation for this class was generated from the following file: