Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ZeroMQPoller Class Reference

Wrapper class for polling ZeroMQ sockets.

This class simplifies calls to poll or ppoll ZeroMQ sockets. It stores the list of sockets to be polled, which means they don't have to be separately carried around by the user. It also parses output and returns an easily digestible vector of events.

Definition at line 26 of file ZeroMQPoller.h.

Public Types

using entry_t = std::tuple< size_t, zmq::event_flags, const zmq::socket_t * >
 
using fd_entry_t = std::tuple< size_t, zmq::event_flags >
 
using fds_t = std::unordered_map< int, fd_entry_t >
 
using free_t = std::deque< int >
 
using sockets_t = std::unordered_map< void *, entry_t >
 

Public Member Functions

 ZeroMQPoller ()=default
 
std::vector< std::pair< size_t, zmq::event_flags > > poll (int timeo=-1)
 Poll the sockets.
 
std::vector< std::pair< size_t, zmq::event_flags > > ppoll (int timeo, const sigset_t *sigmask)
 Poll the sockets with ppoll.
 
size_t register_socket (int fd, zmq::event_flags type)
 Register socket to poll.
 
size_t register_socket (zmq::socket_t &socket, zmq::event_flags type)
 Register socket to poll.
 
size_t size () const
 
size_t unregister_socket (int fd)
 Unregister socket from poller.
 
size_t unregister_socket (zmq::socket_t &socket)
 Unregister socket from poller.
 

Private Attributes

fds_t m_fds
 
free_t m_free
 
std::vector< zmq::pollitem_t > m_items
 
sockets_t m_sockets
 

#include </home/sftnight/build/workspace/root-makedoc-v630/rootspi/rdoc/src/v6-30-00-patches/roofit/roofitZMQ/res/RooFit_ZMQ/ZeroMQPoller.h>

Member Typedef Documentation

◆ entry_t

using ZeroMQPoller::entry_t = std::tuple<size_t, zmq::event_flags, const zmq::socket_t *>

Definition at line 28 of file ZeroMQPoller.h.

◆ fd_entry_t

using ZeroMQPoller::fd_entry_t = std::tuple<size_t, zmq::event_flags>

Definition at line 33 of file ZeroMQPoller.h.

◆ fds_t

using ZeroMQPoller::fds_t = std::unordered_map<int, fd_entry_t>

Definition at line 34 of file ZeroMQPoller.h.

◆ free_t

using ZeroMQPoller::free_t = std::deque<int>

Definition at line 36 of file ZeroMQPoller.h.

◆ sockets_t

using ZeroMQPoller::sockets_t = std::unordered_map<void *, entry_t>

Definition at line 31 of file ZeroMQPoller.h.

Constructor & Destructor Documentation

◆ ZeroMQPoller()

ZeroMQPoller::ZeroMQPoller ( )
default

Member Function Documentation

◆ poll()

std::vector< std::pair< size_t, zmq::event_flags > > ZeroMQPoller::poll ( int  timeo = -1)

Poll the sockets.

Parameters
[in]timeoTimeout in milliseconds. 0 means return immediately. -1 means wait for an event indefinitely.
Returns
A vector of pairs of index and flags; index is the index of the registered fd or socket and flags are 0 (no events), ZMQ_POLLIN or ZMQ_POLLOUT.
Note
This function can throw (from inside zmq::poll), so wrap in try-catch!

Definition at line 37 of file ZeroMQPoller.cpp.

◆ ppoll()

std::vector< std::pair< size_t, zmq::event_flags > > ZeroMQPoller::ppoll ( int  timeo,
const sigset_t *  sigmask 
)

Poll the sockets with ppoll.

By polling with ppoll instead of poll, one can pass along a signal mask to handle POSIX signals properly. See the zmq_ppoll documentation for examples of when this is useful: http://api.zeromq.org/

Parameters
[in]timeoTimeout in milliseconds. 0 means return immediately. -1 means wait for an event indefinitely.
[in]sigmaskA non-nullptr pointer to a signal mask must be constructed and passed to 'sigmask'. See the man page of sigprocmask(2) for more details on this.
Returns
A vector of pairs of index and flags; index is the index of the registered fd or socket and flags are 0 (no events), ZMQ_POLLIN or ZMQ_POLLOUT.
Note
This function can throw (from inside ZMQ::ppoll), so wrap in try-catch!

Definition at line 91 of file ZeroMQPoller.cpp.

◆ register_socket() [1/2]

size_t ZeroMQPoller::register_socket ( int  fd,
zmq::event_flags  type 
)

Register socket to poll.

Adds the socket to the internal list of sockets to poll.

Parameters
[in]fdFile descriptor of socket to register.
[in]typeType of events to poll for. Can be ZMQ_POLLIN, ZMQ_POLLOUT or a bit-wise combination of the two.
Returns
The index of the socket in the poller's internal list. Can be used to match with indices returned from (p)poll.

Definition at line 165 of file ZeroMQPoller.cpp.

◆ register_socket() [2/2]

size_t ZeroMQPoller::register_socket ( zmq::socket_t &  socket,
zmq::event_flags  type 
)

Register socket to poll.

Adds the socket to the internal list of sockets to poll.

Parameters
[in]socketSocket to register.
[in]typeType of events to poll for. Can be ZMQ_POLLIN, ZMQ_POLLOUT or a bit-wise combination of the two.
Returns
The index of the socket in the poller's internal list. Can be used to match with indices returned from (p)poll.

Definition at line 136 of file ZeroMQPoller.cpp.

◆ size()

size_t ZeroMQPoller::size ( ) const

Definition at line 121 of file ZeroMQPoller.cpp.

◆ unregister_socket() [1/2]

size_t ZeroMQPoller::unregister_socket ( int  fd)

Unregister socket from poller.

Removes the socket from the internal list of sockets to poll.

Parameters
[in]fdFile descriptor of socket to unregister.
Returns
The index of the socket in the poller's internal list before removal.

Definition at line 225 of file ZeroMQPoller.cpp.

◆ unregister_socket() [2/2]

size_t ZeroMQPoller::unregister_socket ( zmq::socket_t &  socket)

Unregister socket from poller.

Removes the socket from the internal list of sockets to poll.

Parameters
[in]socketSocket to unregister.
Returns
The index of the socket in the poller's internal list before removal.

Definition at line 191 of file ZeroMQPoller.cpp.

Member Data Documentation

◆ m_fds

fds_t ZeroMQPoller::m_fds
private

Definition at line 55 of file ZeroMQPoller.h.

◆ m_free

free_t ZeroMQPoller::m_free
private

Definition at line 58 of file ZeroMQPoller.h.

◆ m_items

std::vector<zmq::pollitem_t> ZeroMQPoller::m_items
private

Definition at line 53 of file ZeroMQPoller.h.

◆ m_sockets

sockets_t ZeroMQPoller::m_sockets
private

Definition at line 54 of file ZeroMQPoller.h.

  • roofit/roofitZMQ/res/RooFit_ZMQ/ZeroMQPoller.h
  • roofit/roofitZMQ/src/ZeroMQPoller.cpp