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

Classes

class  BorrowedFd
 Non-owning wrapper around a file descriptor. More...
class  EPollPoller
 epoll-based implementation of Poller. More...
class  InotifyWatcher
 Watches filesystem paths using Linux inotify API and dispatches events through callbacks. More...
class  OwnedFd
 Owning RAII wrapper around a file descriptor. More...
class  Poller
 Abstract interface for FD-based event polling. More...
class  PollerFd
 RAII wrapper for the registration of a FD in a Poller. More...
class  SignalFdWatcher
 Watches POSIX signals via signalfd and dispatches them through a callback. More...
class  Timer
 FD-integrated timer utility (timerfd-backed). More...

Typedefs

using FdCallback = std::function<void (BorrowedFd, EventTriggers)>
 Invoked when events occur on a watched file descriptor.
using Callback = std::move_only_function<void ()>
 Generic move-only callback with no arguments.

Enumerations

enum class  EventInterest { Read = 0x01 , Write = 0x02 , ReadClose = 0x04 , OneShot = 0x08 }
 Event types a watcher can subscribe to for a given file descriptor. More...
enum class  EventTrigger {
  Readable = 0x01 , Writable = 0x02 , PeerClosed = 0x04 , Hangup = 0x08 ,
  Error = 0x10
}
 Event types that can be delivered by the poller for a given file descriptor. More...

Functions

void swap (BorrowedFd &fd1, BorrowedFd &fd2) noexcept
 DECLARE_FLAGS (EventInterests, EventInterest)
 DECLARE_FLAGS (EventTriggers, EventTrigger)
uint32_t toNativeEPollEvent (EventInterests events) noexcept
 Convert abstract interests into a native epoll events bitmask.
EventTriggers fromNativeEPollEvent (uint32_t events) noexcept
 Convert a native epoll events bitmask into abstract triggers.
OwnedFd makeOwnedFd (int fd) noexcept
 Create a OwnedFd that will automatically close the given fd on destruction.
void swap (OwnedFd &fd1, OwnedFd &fd2) noexcept
PollerFd makePollerFd (Poller &poller, OwnedFd fd, EventInterests events, FdCallback cb) noexcept
 Create a PollerFd and transfer FD ownership to it.
void swap (PollerFd &fd1, PollerFd &fd2) noexcept

Typedef Documentation

◆ Callback

using dfx::FdWatch::Callback = std::move_only_function<void ()>

Generic move-only callback with no arguments.

◆ FdCallback

using dfx::FdWatch::FdCallback = std::function<void (BorrowedFd, EventTriggers)>

Invoked when events occur on a watched file descriptor.

The callback receives the triggering file descriptor and the set of delivered EventTriggers.

Enumeration Type Documentation

◆ EventInterest

enum class dfx::FdWatch::EventInterest
strong

Event types a watcher can subscribe to for a given file descriptor.

These values are combined into EventInterests to express what the caller wants the poller to monitor.

Notes:

  • Read and write interests are edge-triggered in the dfx FD-watch abstraction.
  • OneShot is a polling-mode modifier: after a notification is delivered, the FD must be re-armed to receive further notifications.
Enumerator
Read 

Monitor readability (edge-triggered).

Write 

Monitor writability (edge-triggered).

ReadClose 

Monitor peer shutdown / read-side closure (e.g. EPOLLRDHUP).

OneShot 

One-shot behavior: guarantee a single notification between explicit re-arms.

◆ EventTrigger

enum class dfx::FdWatch::EventTrigger
strong

Event types that can be delivered by the poller for a given file descriptor.

These values are combined into EventTriggers and represent what happened since the FD was armed.

Some triggers are conditional on being subscribed:

Others are delivered regardless of subscriptions:

Enumerator
Readable 

FD became readable (only if EventInterest::Read is set).

Writable 

FD became writable (only if EventInterest::Write is set).

PeerClosed 

Peer closed its write side / read-side hangup (only if EventInterest::ReadClose is set).

Hangup 

Hangup detected (always delivered when observed).

Error 

Error condition detected (always delivered when observed).

Function Documentation

◆ fromNativeEPollEvent()

EventTriggers dfx::FdWatch::fromNativeEPollEvent ( uint32_t events)
noexcept

Convert a native epoll events bitmask into abstract triggers.

Parameters
eventsA native uint32_t bitmask as returned by epoll_wait / epoll_pwait.
Returns
The corresponding abstract triggers.

◆ makeOwnedFd()

OwnedFd dfx::FdWatch::makeOwnedFd ( int fd)
inlinenodiscardnoexcept

Create a OwnedFd that will automatically close the given fd on destruction.

◆ makePollerFd()

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

Create a PollerFd and transfer FD ownership to it.

◆ toNativeEPollEvent()

uint32_t dfx::FdWatch::toNativeEPollEvent ( EventInterests events)
noexcept

Convert abstract interests into a native epoll events bitmask.

Parameters
eventsThe abstract interests to arm for a file descriptor.
Returns
A native uint32_t bitmask suitable for use with epoll_ctl.