COROIO: NNet::TKqueue Class Reference
COROIO
 
Loading...
Searching...
No Matches
NNet::TKqueue Class Reference

Poller implementation using kqueue (for macOS and FreeBSD). More...

#include <kqueue.hpp>

Inheritance diagram for NNet::TKqueue:
NNet::TPollerBase

Public Types

using TSocket = NNet::TSocket
 Alias for the socket type.
 
using TFileHandle = NNet::TFileHandle
 Alias for the file handle type.
 

Public Member Functions

 TKqueue ()
 Constructs the TKqueue instance.
 
 ~TKqueue ()
 Destroys the TKqueue instance.
 
void Poll ()
 Polls for I/O events using kqueue.
 
- Public Member Functions inherited from NNet::TPollerBase
 TPollerBase ()=default
 Default constructor.
 
 TPollerBase (const TPollerBase &)=delete
 Copying is disabled.
 
TPollerBaseoperator= (const TPollerBase &)=delete
 
unsigned AddTimer (TTime deadline, THandle h)
 Schedules a timer.
 
bool RemoveTimer (unsigned timerId, TTime deadline)
 Removes or cancels a timer.
 
void AddRead (int fd, THandle h)
 Registers a read event on a file descriptor.
 
void AddWrite (int fd, THandle h)
 Registers a write event on a file descriptor.
 
void AddRemoteHup (int fd, THandle h)
 Registers a remote hang-up (RHUP) event.
 
void RemoveEvent (int fd)
 Removes registered events for a specific file descriptor.
 
void RemoveEvent (THandle)
 Removes events associated with a given coroutine handle.
 
auto Sleep (TTime until)
 Suspends execution until the specified time.
 
template<typename Rep, typename Period>
auto Sleep (std::chrono::duration< Rep, Period > duration)
 Overload of Sleep() accepting a duration.
 
auto Yield ()
 Yields execution to the next event loop iteration.
 
void Wakeup (TEvent &&change)
 Wakes up a coroutine waiting on an event.
 
void WakeupReadyHandles ()
 Wakes up all coroutines waiting on ready events.
 
void SetMaxDuration (std::chrono::milliseconds maxDuration)
 Sets the maximum polling duration.
 
auto TimersSize () const
 Returns the number of scheduled timers.
 

Additional Inherited Members

- Protected Member Functions inherited from NNet::TPollerBase
timespec GetTimeout () const
 Computes the poll timeout based on scheduled timers.
 
void Reset ()
 Clears the lists of ready events and pending changes.
 
void ProcessTimers ()
 Processes scheduled timers.
 
- Static Protected Member Functions inherited from NNet::TPollerBase
static constexpr timespec GetMaxDuration (std::chrono::milliseconds duration)
 Computes a timespec from a duration.
 
- Protected Attributes inherited from NNet::TPollerBase
int MaxFd_ = -1
 Highest file descriptor in use.
 
std::vector< TEventChanges_
 Pending changes (registered events).
 
std::vector< TEventReadyEvents_
 Events ready to wake up their coroutines.
 
unsigned TimerId_ = 0
 Counter for generating unique timer IDs.
 
std::priority_queue< TTimerTimers_
 Priority queue for scheduled timers.
 
TTime LastTimersProcessTime_
 Last time timers were processed.
 
unsigned LastFiredTimer_ = (unsigned)(-1)
 ID of the last fired timer.
 
std::chrono::milliseconds MaxDuration_ = std::chrono::milliseconds(100)
 Maximum poll duration.
 
timespec MaxDurationTs_ = GetMaxDuration(MaxDuration_)
 Max duration represented as timespec.
 

Detailed Description

Poller implementation using kqueue (for macOS and FreeBSD).

TKqueue inherits from TPollerBase and provides asynchronous I/O event polling based on the kqueue API available on BSD-based systems (including macOS and FreeBSD). It manages events through an internal list of kevent structures.

The following type aliases are defined for convenience:

Main methods:

  • The constructor and destructor (TKqueue() and ~TKqueue()) handle initialization and cleanup of the kqueue descriptor.
  • Poll() waits for I/O events using kqueue, processes the changes, and updates internal event lists.

Internal data members include:

  • Fd_: The kqueue file descriptor.
  • InEvents_: A container of all registered events.
  • ChangeList_: A vector storing modifications (kevent changes) to be applied.
  • OutEvents_: A vector to collect events returned by kevent().

Constructor & Destructor Documentation

◆ TKqueue()

NNet::TKqueue::TKqueue ( )

Constructs the TKqueue instance.

Initializes the kqueue file descriptor and internal event lists.

◆ ~TKqueue()

NNet::TKqueue::~TKqueue ( )

Destroys the TKqueue instance.

Closes the kqueue descriptor and releases associated resources.

Member Function Documentation

◆ Poll()

void NNet::TKqueue::Poll ( )

Polls for I/O events using kqueue.

This method calls kevent() to wait for events, processes the resulting events from OutEvents_, and updates internal structures accordingly.


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