Zth (libzth)
zth::PollerServer< PollItem_ > Class Template Referenceabstract

Poller to be executed by the Waiter. More...

#include <poller.h>

Inheritance diagram for zth::PollerServer< PollItem_ >:
zth::PollerServerBase zth::PollerInterface zth::UniqueID< PollerInterface > zth::UniqueIDBase

Public Types

typedef PollerServerBase base
 
typedef PollerClientBase Client
 
- Public Types inherited from zth::PollerServerBase
typedef PollerClientBase Client
 

Public Member Functions

 PollerServer ()=default
 Ctor. More...
 
 PollerServer (PollerServer const &)=delete
 
void operator= (PollerServer const &)=delete
 
 PollerServer (PollerServer &&p)=delete
 
void operator= (PollerServer &&p)=delete
 
virtual ~PollerServer () override
 
virtual int migrateTo (PollerServerBase &p) noexcept override
 Move all registered Pollables to another server. More...
 
virtual void reserve (size_t more) override
 Reserve memory to add more pollables. More...
 
int add (Pollable &p, Client *client) noexcept final
 Add a Pollable, that belongs to a given client. More...
 
int add (Pollable &p) noexcept final
 Add a pollable object. More...
 
int remove (Pollable &p, Client *client) noexcept final
 Remove the given Pollable, belonging to the given client. More...
 
void remove (size_t last) noexcept
 Remove the last added Pollables. More...
 
int remove (Pollable &p) noexcept final
 Remove a pollable object. More...
 
void clear () noexcept
 Clear all Pollables. More...
 
bool empty () const noexcept final
 Checks if there is any pollable registered. More...
 
virtual int poll (int timeout_ms) noexcept override
 Poll. More...
 
- Public Member Functions inherited from zth::PollerServerBase
virtual ~PollerServerBase () override=default
 
- Public Member Functions inherited from zth::PollerInterface
virtual ~PollerInterface ()=default
 Dtor. More...
 
int add (std::initializer_list< std::reference_wrapper< Pollable >> l) noexcept
 Add pollable objects. More...
 
- Public Member Functions inherited from zth::UniqueID< PollerInterface >
 UniqueID (UniqueID const &)=delete
 
 UniqueID (UniqueID &&u) noexcept
 
 UniqueID (string const &name)
 
 UniqueID (string &&name)
 
 UniqueID (char const *name=nullptr)
 
UniqueIDoperator= (UniqueID const &)=delete
 
UniqueIDoperator= (UniqueID &&u) noexcept
 
virtual ~UniqueID ()=default
 
void const * normptr () const noexcept
 
uint64_t id () const noexcept
 
string const & name () const noexcept
 
void setName (string const &name)
 
void setName (char const *name)
 
void setName (string &&name)
 
virtual char const * id_str () const override
 

Protected Types

typedef PollItem_ PollItem
 
typedef small_vector< PollItem, 4 > PollItemList
 Type of list of poll things. More...
 

Protected Member Functions

void event (Pollable::Events revents, size_t index) noexcept
 Register an revents for the PollItem at the given index. More...
 
- Protected Member Functions inherited from zth::UniqueIDBase
virtual ~UniqueIDBase ()=default
 

Additional Inherited Members

- Static Public Member Functions inherited from zth::UniqueID< PollerInterface >
static uint64_t getID () noexcept
 

Detailed Description

template<typename PollItem_>
class zth::PollerServer< PollItem_ >

Poller to be executed by the Waiter.

Per-fiber Poller clients can forward their poll request to the server.

poll() typically uses an array of things to do the actual poll on, such as struct pollfd. This class manages the administration of Pollables to these things.

The subclass must implement init() to initialize this thing, and doPoll() to perform the actual poll. Implement deinit() to do cleanup of that thing before destruction.

Template Parameters
PollItem_the item to be used as the actual poll thing

Definition at line 337 of file poller.h.

Member Typedef Documentation

◆ base

template<typename PollItem_ >
typedef PollerServerBase zth::PollerServer< PollItem_ >::base

Definition at line 339 of file poller.h.

◆ Client

template<typename PollItem_ >
typedef PollerClientBase zth::PollerServerBase::Client

Definition at line 275 of file poller.h.

◆ PollItem

template<typename PollItem_ >
typedef PollItem_ zth::PollerServer< PollItem_ >::PollItem
protected

Definition at line 545 of file poller.h.

◆ PollItemList

template<typename PollItem_ >
typedef small_vector<PollItem, 4> zth::PollerServer< PollItem_ >::PollItemList
protected

Type of list of poll things.

Definition at line 548 of file poller.h.

Constructor & Destructor Documentation

◆ PollerServer() [1/3]

template<typename PollItem_ >
zth::PollerServer< PollItem_ >::PollerServer ( )
default

Ctor.

◆ PollerServer() [2/3]

template<typename PollItem_ >
zth::PollerServer< PollItem_ >::PollerServer ( PollerServer< PollItem_ > const &  )
delete

◆ PollerServer() [3/3]

template<typename PollItem_ >
zth::PollerServer< PollItem_ >::PollerServer ( PollerServer< PollItem_ > &&  p)
delete

◆ ~PollerServer()

template<typename PollItem_ >
virtual zth::PollerServer< PollItem_ >::~PollerServer ( )
inlineoverridevirtual

Definition at line 360 of file poller.h.

Member Function Documentation

◆ add() [1/2]

template<typename PollItem_ >
int zth::PollerServer< PollItem_ >::add ( Pollable p)
inlinefinalvirtualnoexcept

Add a pollable object.

Once a pollable is added, do not modify its properties, except for user_data.

Returns
0 on success, otherwise an errno

Implements zth::PollerInterface.

Definition at line 434 of file poller.h.

◆ add() [2/2]

template<typename PollItem_ >
int zth::PollerServer< PollItem_ >::add ( Pollable p,
Client client 
)
inlinefinalvirtualnoexcept

Add a Pollable, that belongs to a given client.

client can be nullptr.

Returns
0 on success, otherwise an errno

Implements zth::PollerServerBase.

Definition at line 405 of file poller.h.

◆ clear()

template<typename PollItem_ >
void zth::PollerServer< PollItem_ >::clear ( )
inlinenoexcept

Clear all Pollables.

It does not release the allocated memory.

Definition at line 513 of file poller.h.

◆ empty()

template<typename PollItem_ >
bool zth::PollerServer< PollItem_ >::empty ( ) const
inlinefinalvirtualnoexcept

Checks if there is any pollable registered.

Implements zth::PollerInterface.

Definition at line 522 of file poller.h.

◆ event()

template<typename PollItem_ >
void zth::PollerServer< PollItem_ >::event ( Pollable::Events  revents,
size_t  index 
)
inlineprotectednoexcept

Register an revents for the PollItem at the given index.

This function should be called by doPoll(). Events are forwarded to the client registered with the Pollable.

Definition at line 557 of file poller.h.

◆ migrateTo()

template<typename PollItem_ >
virtual int zth::PollerServer< PollItem_ >::migrateTo ( PollerServerBase p)
inlineoverridevirtualnoexcept

Move all registered Pollables to another server.

Returns
0 on success, otherwise an errno

Implements zth::PollerServerBase.

Definition at line 366 of file poller.h.

◆ operator=() [1/2]

template<typename PollItem_ >
void zth::PollerServer< PollItem_ >::operator= ( PollerServer< PollItem_ > &&  p)
delete

◆ operator=() [2/2]

template<typename PollItem_ >
void zth::PollerServer< PollItem_ >::operator= ( PollerServer< PollItem_ > const &  )
delete

◆ poll()

template<typename PollItem_ >
virtual int zth::PollerServer< PollItem_ >::poll ( int  timeout_ms)
inlineoverridevirtualnoexcept

Poll.

The Pollables with events are not saved in the server, but these are forwarded to the registered Client.

Returns
0 when a Pollable returned an event, otherwise an errno

Implements zth::PollerServerBase.

Definition at line 527 of file poller.h.

◆ remove() [1/3]

template<typename PollItem_ >
int zth::PollerServer< PollItem_ >::remove ( Pollable p)
inlinefinalvirtualnoexcept

Remove a pollable object.

Returns
0 on success, otherwise an errno

Implements zth::PollerInterface.

Definition at line 503 of file poller.h.

◆ remove() [2/3]

template<typename PollItem_ >
int zth::PollerServer< PollItem_ >::remove ( Pollable p,
Client client 
)
inlinefinalvirtualnoexcept

Remove the given Pollable, belonging to the given client.

client must match the one that was specified during add().

Returns
0 on success, otherwise an errno

Implements zth::PollerServerBase.

Definition at line 440 of file poller.h.

◆ remove() [3/3]

template<typename PollItem_ >
void zth::PollerServer< PollItem_ >::remove ( size_t  last)
inlinenoexcept

Remove the last added Pollables.

Definition at line 489 of file poller.h.

◆ reserve()

template<typename PollItem_ >
virtual void zth::PollerServer< PollItem_ >::reserve ( size_t  more)
inlineoverridevirtual

Reserve memory to add more pollables.

Exceptions
std::bad_allocwhen allocation fails

Implements zth::PollerInterface.

Definition at line 399 of file poller.h.


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