Belle II Software light-2406-ragdoll
|
A helper class for creating ZMQ sockets keeping track of the ZMQ context and terminating it if needed. More...
#include <ZMQParent.h>
Public Member Functions | |
~ZMQParent () | |
Destroy the parent by terminating the ZMQ context. | |
void | terminate () |
Terminate the parent manually (before calling its destructor). You probably do not need to do this. | |
template<int AZMQType> | |
std::unique_ptr< zmq::socket_t > | createSocket (const std::string &socketAddress, bool bind) |
Create a socket of the given type with the given address and bind or not bind it. | |
template<int AZMQType> | |
std::unique_ptr< zmq::socket_t > | createSocket (const std::string &socketAddress) |
Create a socket of the given type while deciding on the bind behaviour via the address. | |
void | reset () |
Expert function: Reset the parent without context closing. ATTENTION: which will not clean up properly! Do only use after forks. | |
Static Public Member Functions | |
template<class AZMQMessage > | |
static void | send (std::unique_ptr< zmq::socket_t > &socket, AZMQMessage message) |
Send a given message over the given created socket. You need to move in the message for zero-copy. | |
static unsigned int | poll (const std::vector< zmq::socket_t * > &socketList, int timeout) |
Poll function. | |
static std::string | createIdentity (unsigned int pid=0) |
Create a unique ZMQ identity in the form <hostname>_<pid> (if pid is 0, use the current processes PID). | |
Private Member Functions | |
void | initialize () |
Initialize the parent by creating the context. | |
Private Attributes | |
std::unique_ptr< zmq::context_t > | m_context |
ZMQ context. | |
A helper class for creating ZMQ sockets keeping track of the ZMQ context and terminating it if needed.
Basically just a convenience wrapper around a zmq::context_t.
In your application, you should have only a single instance of a ZMQParent, for example a std::shared_ptr in your main class. Use it to create sockets and let the automatic destruction at the end call the cleanup functions properly. After the parent is closed, all its sockets are also invalid. The parent gets initialized on first socket creation.
Only in very rare cases you need to not terminate this parent, e.g. when you create a parent and then fork (because you do not want to close the parent twice). This however is an expert function.
Definition at line 39 of file ZMQParent.h.
~ZMQParent | ( | ) |
Destroy the parent by terminating the ZMQ context.
Definition at line 14 of file ZMQParent.cc.
|
static |
Create a unique ZMQ identity in the form <hostname>_<pid> (if pid is 0, use the current processes PID).
Definition at line 32 of file ZMQParent.cc.
|
private |
Initialize the parent by creating the context.
Definition at line 44 of file ZMQParent.cc.
|
static |
Poll function.
Poll on the given socket pointers and return a bitmask indicating which sockets received a message. If the poll is interrupted (e.g. by a system interrupt), return 0.
If the timeout is positive, wait maximal timeout milliseconds before returning (even if there is no message in the sockets). If the timeout is 0, only check once and return immediately. If the timeout is -1, wait infinitely.
Definition at line 56 of file ZMQParent.cc.
void reset | ( | ) |
Expert function: Reset the parent without context closing. ATTENTION: which will not clean up properly! Do only use after forks.
Definition at line 27 of file ZMQParent.cc.
void terminate | ( | ) |
Terminate the parent manually (before calling its destructor). You probably do not need to do this.
Definition at line 19 of file ZMQParent.cc.
|
private |
ZMQ context.
Definition at line 98 of file ZMQParent.h.