8#include <framework/pcore/zmq/utils/ZMQParent.h>
34 char hostname[HOST_NAME_MAX];
35 gethostname(hostname, HOST_NAME_MAX);
41 return std::string(hostname) +
"_" + std::to_string(pid);
49 m_context = std::make_unique<zmq::context_t>(1);
52#if defined(__GNUC__) && !defined(__clang__)
53#pragma GCC diagnostic push
54#pragma GCC diagnostic ignored "-Wstack-usage="
56unsigned int ZMQParent::poll(
const std::vector<zmq::socket_t*>& socketList,
int timeout)
58 B2ASSERT(
"Only allow to poll on maximal 8 sockets at the same time!", socketList.size() <= 8);
59 std::bitset<8> return_bitmask;
60 zmq::pollitem_t items[socketList.size()];
62 for (
unsigned int i = 0; i < socketList.size(); i++) {
63 items[i].socket =
static_cast<void*
>(*socketList[i]);
64 items[i].events = ZMQ_POLLIN;
69 zmq::poll(items, socketList.size(), timeout);
71 for (
unsigned int i = 0; i < socketList.size(); i++) {
72 return_bitmask[i] =
static_cast<bool>(items[i].revents & ZMQ_POLLIN);
74 return return_bitmask.to_ulong();
75 }
catch (zmq::error_t& error) {
76 if (error.num() == EINTR) {
84#if defined(__GNUC__) && !defined(__clang__)
85#pragma GCC diagnostic pop
void initialize()
Initialize the parent by creating the context.
static unsigned int poll(const std::vector< zmq::socket_t * > &socketList, int timeout)
Poll function.
void terminate()
Terminate the parent manually (before calling its destructor). You probably do not need to do this.
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...
std::unique_ptr< zmq::context_t > m_context
ZMQ context.
~ZMQParent()
Destroy the parent by terminating the ZMQ context.
void reset()
Expert function: Reset the parent without context closing. ATTENTION: which will not clean up properl...
Abstract base class for different kinds of events.