![]() |
dfx 0.1.0
Linux-based dynamic dataflow executor
|
RAII wrapper for the registration of a FD in a Poller. More...
#include <dfx-fdwatch/PollerFd.hpp>
Public Member Functions | |
| PollerFd () noexcept=default | |
| Constructs an empty handle with no poller association and no FD. | |
| PollerFd (Utils::OwnedFd fd) noexcept | |
Takes ownership of fd but do not attach it to any poller. | |
| PollerFd (Poller &poller, int fd, EventInterests events, FdCallback cb) | |
Takes ownership of fd and registers it to poller. | |
| PollerFd (Poller &poller, Utils::OwnedFd fd, EventInterests events, FdCallback cb) | |
Takes ownership of fd and registers it to poller. | |
| PollerFd (PollerFd &&other) noexcept | |
| Move constructor. | |
| DFX_DISABLE_COPY (PollerFd) | |
| Copying is disabled because this type owns the FD. | |
| ~PollerFd () | |
| Destructor. | |
| PollerFd & | operator= (PollerFd &&other) noexcept |
| Move assignment. | |
| bool | operator== (PollerFd const &) const noexcept=delete |
| bool | operator!= (PollerFd const &) const noexcept=delete |
| bool | operator== (int fd) const noexcept |
| bool | operator== (Utils::BorrowedFd const &fd) const noexcept |
| void | swap (PollerFd &other) noexcept |
| Utils::BorrowedFd | borrow () const noexcept |
| Returns a non-owning view of the underlying FD. | |
| Poller * | poller () const noexcept |
| Returns the poller this FD is currently associated with (if any). | |
| bool | isRegistered () const noexcept |
| Returns whether this FD is currently registered in a poller. | |
| int | get () const noexcept |
| Returns the raw integer FD owned by this object. | |
| bool | hasValidFd () const noexcept |
| Returns true if the internal fd is valid. | |
| void | attach (Poller &poller, Utils::OwnedFd fd, EventInterests events, FdCallback cb) |
Attaches this object to poller and adopts fd, registering it. | |
| void | registerTo (Poller &poller, EventInterests events, FdCallback cb) |
Registers the currently owned FD into poller. | |
| void | migrateTo (Poller &poller, EventInterests events, FdCallback cb) |
Moves the registration from the current poller to poller. | |
| void | updateEvents (EventInterests events) |
| Update the list of event that this fd is attached to. | |
| void | deregister () noexcept |
| Deregisters this FD from its poller (if registered). | |
| void | reset () noexcept |
| Fully releases resources: deregisters (if needed), drops poller association, and closes/releases the owned FD. | |
RAII wrapper for the registration of a FD in a Poller.
PollerFd owns a file descriptor (via dfx::Utils::OwnedFd) and can register/deregister it into a Poller along with a callback and event interests.
This type is move-only: copying is disabled because it owns the underlying file descriptor and represents a single registration lifetime.
Typical usage:
|
defaultnoexcept |
Constructs an empty handle with no poller association and no FD.
The instance is not registered and poller() returns null.
|
explicitnoexcept |
Takes ownership of fd but do not attach it to any poller.
| fd | Owned file descriptor. |
| dfx::FdWatch::PollerFd::PollerFd | ( | Poller & | poller, |
| int | fd, | ||
| EventInterests | events, | ||
| FdCallback | cb ) |
Takes ownership of fd and registers it to poller.
| poller | Poller in which the FD should be registered. |
| fd | Raw file descriptor to adopt. |
| events | Events of interest (e.g. readable/writable). |
| cb | Callback invoked by the poller when events occur. |
| dfx::FdWatch::PollerFd::PollerFd | ( | Poller & | poller, |
| Utils::OwnedFd | fd, | ||
| EventInterests | events, | ||
| FdCallback | cb ) |
|
noexcept |
Move constructor.
Transfers FD ownership and any poller association/registration state. The moved-from object becomes empty/unregistered.
| dfx::FdWatch::PollerFd::~PollerFd | ( | ) |
Destructor.
Releases the owned FD. If the instance is registered, it will be deregistered as part of cleanup and the FD will be subsequently closed
| void dfx::FdWatch::PollerFd::attach | ( | Poller & | poller, |
| Utils::OwnedFd | fd, | ||
| EventInterests | events, | ||
| FdCallback | cb ) |
Attaches this object to poller and adopts fd, registering it.
This is typically used to initialize a default-constructed instance, or to reinitialize an existing instance after reset().
|
inlinenodiscardnoexcept |
Returns a non-owning view of the underlying FD.
Useful for APIs that require a dfx::Utils::BorrowedFd without transferring ownership.
|
noexcept |
Deregisters this FD from its poller (if registered).
Keeps ownership of the FD (i.e. do not close it) but clears the registration state.
| dfx::FdWatch::PollerFd::DFX_DISABLE_COPY | ( | PollerFd | ) |
Copying is disabled because this type owns the FD.
|
inlinenoexcept |
Returns the raw integer FD owned by this object.
|
inlinenoexcept |
Returns true if the internal fd is valid.
The internal fd may be valid but not registered.
|
inlinenoexcept |
Returns whether this FD is currently registered in a poller.
| void dfx::FdWatch::PollerFd::migrateTo | ( | Poller & | poller, |
| EventInterests | events, | ||
| FdCallback | cb ) |
Moves the registration from the current poller to poller.
Intended for cases where the FD must keep being watched but the poller instance changes (e.g. moving an object between reactors/threads).
| poller | Destination poller. |
| events | New events of interest. |
| cb | Callback invoked when events occur. |
Move assignment.
Releases current resources (if any), then transfers ownership/registration state from other.
|
inlinenoexcept |
Returns the poller this FD is currently associated with (if any).
| void dfx::FdWatch::PollerFd::registerTo | ( | Poller & | poller, |
| EventInterests | events, | ||
| FdCallback | cb ) |
Registers the currently owned FD into poller.
Unlike attach(), this does not adopt a new FD; it uses the one already owned. And unlike migrateTo(), the FD must not already be registered to a poller.
|
noexcept |
| void dfx::FdWatch::PollerFd::updateEvents | ( | EventInterests | events | ) |
Update the list of event that this fd is attached to.
Note that the callback is not touched by this call and will be called if any of the new events is triggered.
| events | The new list of event to listen for. |