8#include <framework/pcore/zmq/utils/ZMQAddressUtils.h>
16 std::string randomName()
18 auto randchar = []() ->
char {
19 const char charset[] =
"abcdefghijklmnopqrstuvwxyz";
20 const size_t max_index = (
sizeof(charset) - 1);
21 return charset[gRandom->Integer(max_index)];
24 const unsigned int length = 4;
25 std::string str(length, 0);
26 std::generate_n(str.begin(), length, randchar);
30 std::string randomPort()
33 const unsigned int port = 5000 + gRandom->Integer(1000);
34 return std::to_string(port);
40 std::string socket_name =
"tcp://" + hostname +
":" + randomPort();
47 std::string socket_name =
"ipc:///tmp/basf2_socket_" + randomName() +
".socket";
48 while (std::ifstream(socket_name)) {
49 socket_name =
"ipc://basf2_socket_" + randomName() +
".socket";
57 const std::string& prefix =
"tcp://";
58 if (socketAddress.compare(0, prefix.size(), prefix) == 0) {
59 if (socketPart == ZMQAddressType::c_input) {
60 return socketAddress +
"0";
62 return socketAddress +
"1";
64 return socketAddress +
"2";
66 return socketAddress +
"3";
68 return socketAddress +
"4";
71 if (socketPart == ZMQAddressType::c_input) {
72 return socketAddress +
"_input";
74 return socketAddress +
"_output";
76 return socketAddress +
"_pub";
78 return socketAddress +
"_sub";
80 return socketAddress +
"_control";
static std::string randomSocketName()
Generate a random socket name in the form ipc:///socketname.
static std::string getSocketAddress(const std::string &socketAddress, ZMQAddressType socketPart)
Create a full socket address for the given type from a random socket address, ba adding a suffix.
ZMQAddressType
The type of a ZMQ socket address (which socket to use)
@ c_sub
Multicast publish socket.
@ c_control
Multicast subscribe socket.
Abstract base class for different kinds of events.