qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
qb::io::epoll::Poller< _MAX_EVENTS > Class Template Reference

High-level epoll event poller. More...

#include <epoll.h>

Inheritance diagram for qb::io::epoll::Poller< _MAX_EVENTS >:
Collaboration diagram for qb::io::epoll::Poller< _MAX_EVENTS >:

Public Member Functions

 Poller ()
 Constructor.
 Poller (Poller const &)=delete
 Copy constructor (deleted)
 ~Poller ()
 Destructor.
template<typename _Func>
void wait (_Func const &func, int const timeout=0)
 Wait for events and process them.
Public Member Functions inherited from qb::io::epoll::Proxy
 Proxy ()=default
 Default constructor.
 Proxy (const int epoll)
 Constructor.
 Proxy (Proxy const &)=default
 Copy constructor.
int ctl (item_type &item) const
 Modify an existing file descriptor in the epoll set.
int add (item_type &item) const
 Add a new file descriptor to the epoll set.
int remove (item_type const &item)
 Remove a file descriptor from the epoll set.

Additional Inherited Members

Public Types inherited from qb::io::epoll::Proxy
using item_type = epoll_event
 Type alias for epoll event item.
Protected Attributes inherited from qb::io::epoll::Proxy
int _epoll
 The epoll file descriptor.

Detailed Description

template<std::size_t _MAX_EVENTS = 4096>
class qb::io::epoll::Poller< _MAX_EVENTS >

High-level epoll event poller.

This template class provides a convenient interface for using epoll to wait for events on multiple file descriptors. It handles the creation and destruction of the epoll file descriptor and provides a simple callback-based interface for event handling.

Note
Available only on Linux >= 2.6
Template Parameters
_MAX_EVENTSMaximum number of events to handle at once

Constructor & Destructor Documentation

◆ Poller() [1/2]

template<std::size_t _MAX_EVENTS = 4096>
qb::io::epoll::Poller< _MAX_EVENTS >::Poller ( )
inline

Constructor.

Creates a new epoll instance with the specified maximum number of events. Throws a runtime_error if the epoll creation fails.

◆ Poller() [2/2]

template<std::size_t _MAX_EVENTS = 4096>
qb::io::epoll::Poller< _MAX_EVENTS >::Poller ( Poller< _MAX_EVENTS > const & )
delete

Copy constructor (deleted)

Epoll file descriptors should not be shared between objects.

◆ ~Poller()

template<std::size_t _MAX_EVENTS = 4096>
qb::io::epoll::Poller< _MAX_EVENTS >::~Poller ( )
inline

Destructor.

Closes the epoll file descriptor.

Member Function Documentation

◆ wait()

template<std::size_t _MAX_EVENTS = 4096>
template<typename _Func>
void qb::io::epoll::Poller< _MAX_EVENTS >::wait ( _Func const & func,
int const timeout = 0 )
inline

Wait for events and process them.

This method waits for events on the epoll file descriptor and calls the provided function for each event that occurs.

Template Parameters
_FuncType of the callback function
Parameters
funcCallback function to handle events
timeoutMaximum time to wait in milliseconds (0 = return immediately, -1 = wait indefinitely)