zmqpp 4.1.2
C++ bindings for 0mq (libzmq)
Loading...
Searching...
No Matches
zmqpp::poller Class Reference

Polling wrapper. More...

#include <poller.hpp>

Collaboration diagram for zmqpp::poller:

Public Types

enum  { wait_forever = -1 }
 
enum  : short {
  poll_none = 0 , poll_in = ZMQ_POLLIN , poll_out = ZMQ_POLLOUT , poll_error = ZMQ_POLLERR ,
  poll_pri = ZMQ_POLLPRI
}
 

Public Member Functions

 poller ()
 Construct an empty polling model.
 
 ~poller ()
 Cleanup poller.
 
void add (socket_t &socket, short const event=poll_in)
 Add a socket to the polling model and set which events to monitor.
 
void add (raw_socket_t const descriptor, short const event=poll_in|poll_error)
 Add a standard socket to the polling model and set which events to monitor.
 
void add (zmq_pollitem_t const &item)
 Add a zmq_pollitem_t to the poller; Events to monitor are already configured.
 
bool has (socket_t const &socket)
 Check if we are monitoring a given socket with this poller.
 
bool has (raw_socket_t const descriptor)
 Check if we are monitoring a given standard socket with this poller.
 
bool has (zmq_pollitem_t const &item)
 Check if we are monitoring a given pollitem.
 
void remove (socket_t const &socket)
 Stop monitoring a socket.
 
void remove (raw_socket_t const descriptor)
 Stop monitoring a standard socket.
 
void remove (zmq_pollitem_t const &item)
 Stop monitoring a zmq_pollitem_t.
 
void check_for (socket_t const &socket, short const event)
 Update the monitored event flags for a given socket.
 
void check_for (raw_socket_t const descriptor, short const event)
 
void check_for (zmq_pollitem_t const &item, short const event)
 Update the monitored event flags for a given zmq_pollitem_t.
 
bool poll (long timeout=wait_forever)
 Poll for monitored events.
 
short events (socket_t const &socket) const
 Get the event flags triggered for a socket.
 
short events (raw_socket_t const descriptor) const
 Get the event flags triggered for a standard socket.
 
short events (zmq_pollitem_t const &item) const
 Get the event flags triggered for a zmq_pollitem_t.
 
template<typename Watched >
bool has_input (Watched const &watchable) const
 Check either a standard socket or zmq socket for input events.
 
template<typename Watched >
bool has_output (Watched const &watchable) const
 Check either a standard socket or zmq socket for output events.
 
template<typename Watched >
bool has_error (Watched const &watchable) const
 Check a standard socket (file descriptor or SOCKET).
 

Private Member Functions

void reindex (size_t const index)
 

Private Attributes

std::vector< zmq_pollitem_t > _items
 
std::unordered_map< void *, size_t > _index
 
std::unordered_map< raw_socket_t, size_t > _fdindex
 

Detailed Description

Polling wrapper.

Allows access to polling for any number of zmq sockets or standard sockets.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
wait_forever 

Block forever flag, default setting.

◆ anonymous enum

anonymous enum : short
Enumerator
poll_none 

No polling flags set.

poll_in 

Monitor inbound flag.

poll_out 

Monitor output flag.

poll_error 

Monitor error flag.
Only for file descriptors.

poll_pri 

Priority input flag.
Only for file descriptors. See POLLPRI)

Constructor & Destructor Documentation

◆ poller()

zmqpp::poller::poller ( )

Construct an empty polling model.

◆ ~poller()

zmqpp::poller::~poller ( )

Cleanup poller.

Any sockets will need to be closed separately.

Member Function Documentation

◆ add() [1/3]

void zmqpp::poller::add ( raw_socket_t const descriptor,
short const event = poll_in | poll_error )

Add a standard socket to the polling model and set which events to monitor.

Parameters
descriptorthe raw socket to monitor (SOCKET under Windows, a file descriptor otherwise).
eventthe event flags to monitor.

◆ add() [2/3]

void zmqpp::poller::add ( socket_t & socket,
short const event = poll_in )

Add a socket to the polling model and set which events to monitor.

Parameters
socketthe socket to monitor.
eventthe event flags to monitor on the socket.

◆ add() [3/3]

void zmqpp::poller::add ( zmq_pollitem_t const & item)

Add a zmq_pollitem_t to the poller; Events to monitor are already configured.

If the zmq_pollitem_t has a null socket pointer it is added to the fdindex, otherwise it is added to the socket index.

Parameters
itemthe pollitem to be added

◆ check_for() [1/3]

void zmqpp::poller::check_for ( raw_socket_t const descriptor,
short const event )

Update the monitored event flags for a given standard socket.

Parameters
descriptorthe raw socket to update event flags (SOCKET under Windows, a file descriptor otherwise).
eventthe event flags to monitor on the socket.

◆ check_for() [2/3]

void zmqpp::poller::check_for ( socket_t const & socket,
short const event )

Update the monitored event flags for a given socket.

Parameters
socketthe socket to update event flags.
eventthe event flags to monitor on the socket.

◆ check_for() [3/3]

void zmqpp::poller::check_for ( zmq_pollitem_t const & item,
short const event )

Update the monitored event flags for a given zmq_pollitem_t.

Parameters
itemthe item to change event flags for.
eventthe event flags to monitor on the socket.

◆ events() [1/3]

short zmqpp::poller::events ( raw_socket_t const descriptor) const

Get the event flags triggered for a standard socket.

Parameters
descriptorthe raw socket to get triggered event flags for (SOCKET under Windows, a file descriptor otherwise).
Returns
the event flags.

◆ events() [2/3]

short zmqpp::poller::events ( socket_t const & socket) const

Get the event flags triggered for a socket.

Parameters
socketthe socket to get triggered event flags for.
Returns
the event flags.

◆ events() [3/3]

short zmqpp::poller::events ( zmq_pollitem_t const & item) const

Get the event flags triggered for a zmq_pollitem_t.

Parameters
itemthe pollitem to get triggered event flags for.
Returns
the event flags.

◆ has() [1/3]

bool zmqpp::poller::has ( raw_socket_t const descriptor)

Check if we are monitoring a given standard socket with this poller.

Parameters
descriptorthe raw socket to check for.
Returns
true if it is there.

◆ has() [2/3]

bool zmqpp::poller::has ( socket_t const & socket)

Check if we are monitoring a given socket with this poller.

Parameters
socketthe socket to check.
Returns
true if it is there.

◆ has() [3/3]

bool zmqpp::poller::has ( zmq_pollitem_t const & item)

Check if we are monitoring a given pollitem.

We assume the pollitem is a socket if it's socket is a non null pointer; otherwise, it is considered as a file descriptor.

Parameters
itemthe pollitem to check for
Returns
true if it is there.

◆ has_error()

template<typename Watched >
bool zmqpp::poller::has_error ( Watched const & watchable) const
inline

Check a standard socket (file descriptor or SOCKET).

Templated helper method that calls through to event and checks for a given flag

Technically this template works for sockets as well but the error flag is never set for sockets so I have no idea why someone would call it.

Parameters
watchablea standard socket known to the poller.
Returns
true if there is an error.

◆ has_input()

template<typename Watched >
bool zmqpp::poller::has_input ( Watched const & watchable) const
inline

Check either a standard socket or zmq socket for input events.

Templated helper method that calls through to event and checks for a given flag

Parameters
watchableeither a standard socket or socket known to the poller.
Returns
true if there is input.

◆ has_output()

template<typename Watched >
bool zmqpp::poller::has_output ( Watched const & watchable) const
inline

Check either a standard socket or zmq socket for output events.

Templated helper method that calls through to event and checks for a given flag

Parameters
watchableeither a standard socket or zmq socket known to the poller.
Returns
true if there is output.

◆ poll()

bool zmqpp::poller::poll ( long timeout = wait_forever)

Poll for monitored events.

By default this method will block forever or until at least one of the monitored sockets or file descriptors has events.

If a timeout is set and was reached then this function returns false.

Parameters
timeoutmilliseconds to timeout.
Returns
true if there is an event..

◆ reindex()

void zmqpp::poller::reindex ( size_t const index)
private

◆ remove() [1/3]

void zmqpp::poller::remove ( raw_socket_t const descriptor)

Stop monitoring a standard socket.

Parameters
descriptorthe raw socket to stop monitoring (SOCKET under Windows, a file descriptor otherwise).

◆ remove() [2/3]

void zmqpp::poller::remove ( socket_t const & socket)

Stop monitoring a socket.

Parameters
socketthe socket to stop monitoring.

◆ remove() [3/3]

void zmqpp::poller::remove ( zmq_pollitem_t const & item)

Stop monitoring a zmq_pollitem_t.

Parameters
itemthe pollitem to stop monitoring.

Member Data Documentation

◆ _fdindex

std::unordered_map<raw_socket_t, size_t> zmqpp::poller::_fdindex
private

◆ _index

std::unordered_map<void *, size_t> zmqpp::poller::_index
private

◆ _items

std::vector<zmq_pollitem_t> zmqpp::poller::_items
private

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