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

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 (Poller &poller, int fd, EventInterests events, FdCallback cb)
 Takes ownership of fd and registers it to poller.
 PollerFd (Poller &poller, OwnedFd fd, EventInterests events, FdCallback cb)
 Takes ownership of fd and registers it to poller.
 PollerFd (PollerFd &&other) noexcept
 Move constructor.
 DISABLE_COPY (PollerFd)
 Copying is disabled because this type owns the FD.
 ~PollerFd ()
 Destructor.
PollerFdoperator= (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== (BorrowedFd const &fd) const noexcept
void swap (PollerFd &other) noexcept
BorrowedFd borrow () const noexcept
 Returns a non-owning view of the underlying FD.
Pollerpoller () 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.
void attach (Poller &poller, 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 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.

Detailed Description

RAII wrapper for the registration of a FD in a Poller.

PollerFd owns a file descriptor (via 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:

  • Store it as default constructed member of a class
  • Call attach() to take ownership and register in the poller
  • Either let it be until destruction or explicitly reset() it
Note
poller() may be null when default-constructed, moved-from, or after reset().

Constructor & Destructor Documentation

◆ PollerFd() [1/4]

dfx::FdWatch::PollerFd::PollerFd ( )
defaultnoexcept

Constructs an empty handle with no poller association and no FD.

The instance is not registered and poller() returns null.

◆ PollerFd() [2/4]

dfx::FdWatch::PollerFd::PollerFd ( Poller & poller,
int fd,
EventInterests events,
FdCallback cb )

Takes ownership of fd and registers it to poller.

Parameters
pollerPoller in which the FD should be registered.
fdRaw file descriptor to adopt.
eventsEvents of interest (e.g. readable/writable).
cbCallback invoked by the poller when events occur.
Note
The provided integer FD is adopted (owned) by this object.

◆ PollerFd() [3/4]

dfx::FdWatch::PollerFd::PollerFd ( Poller & poller,
OwnedFd fd,
EventInterests events,
FdCallback cb )

Takes ownership of fd and registers it to poller.

Parameters
pollerPoller in which the FD should be registered.
fdOwned file descriptor.
eventsEvents of interest (e.g. readable/writable).
cbCallback invoked by the poller when events occur.

◆ PollerFd() [4/4]

dfx::FdWatch::PollerFd::PollerFd ( PollerFd && other)
noexcept

Move constructor.

Transfers FD ownership and any poller association/registration state. The moved-from object becomes empty/unregistered.

◆ ~PollerFd()

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

Member Function Documentation

◆ attach()

void dfx::FdWatch::PollerFd::attach ( Poller & poller,
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().

Parameters
pollerPoller in which the FD should be registered.
fdOwned file descriptor to adopt.
eventsEvents of interest.
cbCallback invoked when events occur.

◆ borrow()

BorrowedFd dfx::FdWatch::PollerFd::borrow ( ) const
inlinenodiscardnoexcept

Returns a non-owning view of the underlying FD.

Useful for APIs that require a BorrowedFd without transferring ownership.

Returns
A BorrowedFd referring to this instance.

◆ deregister()

void dfx::FdWatch::PollerFd::deregister ( )
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.

◆ DISABLE_COPY()

dfx::FdWatch::PollerFd::DISABLE_COPY ( PollerFd )

Copying is disabled because this type owns the FD.

◆ get()

int dfx::FdWatch::PollerFd::get ( ) const
inlinenoexcept

Returns the raw integer FD owned by this object.

Returns
The owned FD value, or an invalid value depending on OwnedFd semantics.

◆ isRegistered()

bool dfx::FdWatch::PollerFd::isRegistered ( ) const
inlinenoexcept

Returns whether this FD is currently registered in a poller.

◆ migrateTo()

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

Parameters
pollerDestination poller.
eventsNew events of interest.
cbCallback invoked when events occur.

◆ operator=()

PollerFd & dfx::FdWatch::PollerFd::operator= ( PollerFd && other)
noexcept

Move assignment.

Releases current resources (if any), then transfers ownership/registration state from other.

◆ poller()

Poller * dfx::FdWatch::PollerFd::poller ( ) const
inlinenoexcept

Returns the poller this FD is currently associated with (if any).

Returns
Pointer to the poller, or null if not attached/registered.

◆ registerTo()

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.

Parameters
pollerPoller in which the FD should be registered.
eventsEvents of interest.
cbCallback invoked when events occur.

◆ reset()

void dfx::FdWatch::PollerFd::reset ( )
noexcept

Fully releases resources: deregisters (if needed), drops poller association, and closes/releases the owned FD.

After reset(), the instance behaves like a default-constructed PollerFd.


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