zmqpp  4.1.2
C++ bindings for 0mq (libzmq)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
zmqpp::poller Class Reference

Polling wrapper. More...

#include <poller.hpp>

Collaboration diagram for zmqpp::poller:
Collaboration graph
[legend]

Public Member Functions

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

Static Public Attributes

static const long wait_forever = -1
 
static const short poll_none = 0
 
static const short poll_in = ZMQ_POLLIN
 
static const short poll_out = ZMQ_POLLOUT
 
static const short poll_error = ZMQ_POLLERR
 
static const short poll_pri = ZMQ_POLLPRI
 

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.

Constructor & Destructor Documentation

zmqpp::poller::poller ( )

Construct an empty polling model.

zmqpp::poller::~poller ( )

Cleanup poller.

Any sockets will need to be closed separately.

Member Function Documentation

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.
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.
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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..
void zmqpp::poller::reindex ( size_t const  index)
private
void zmqpp::poller::remove ( socket_t const &  socket)

Stop monitoring a socket.

Parameters
socketthe socket to stop monitoring.
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).
void zmqpp::poller::remove ( zmq_pollitem_t const &  item)

Stop monitoring a zmq_pollitem_t.

Parameters
itemthe pollitem to stop monitoring.

Member Data Documentation

std::unordered_map<raw_socket_t, size_t> zmqpp::poller::_fdindex
private
std::unordered_map<void *, size_t> zmqpp::poller::_index
private
std::vector<zmq_pollitem_t> zmqpp::poller::_items
private
const short zmqpp::poller::poll_error = ZMQ_POLLERR
static

Monitor error flag.
Only for file descriptors.

const short zmqpp::poller::poll_in = ZMQ_POLLIN
static

Monitor inbound flag.

const short zmqpp::poller::poll_none = 0
static

No polling flags set.

const short zmqpp::poller::poll_out = ZMQ_POLLOUT
static

Monitor output flag.

const short zmqpp::poller::poll_pri = ZMQ_POLLPRI
static

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

const long zmqpp::poller::wait_forever = -1
static

Block forever flag, default setting.


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