2018-05-11 11:43:41 +02:00
|
|
|
#pragma once
|
|
|
|
|
2018-09-23 18:14:25 +02:00
|
|
|
#include <catch.hpp>
|
2018-05-11 11:43:41 +02:00
|
|
|
#include <zmq.hpp>
|
|
|
|
|
2018-07-05 00:46:47 +02:00
|
|
|
#if defined(ZMQ_CPP11)
|
2018-05-11 11:43:41 +02:00
|
|
|
|
2020-03-24 09:33:50 +01:00
|
|
|
inline std::string bind_ip4_loopback(zmq::socket_t &socket)
|
2018-05-11 11:43:41 +02:00
|
|
|
{
|
2020-03-24 09:33:50 +01:00
|
|
|
socket.bind("tcp://127.0.0.1:*");
|
|
|
|
std::string endpoint(100, ' ');
|
|
|
|
endpoint.resize(socket.get(zmq::sockopt::last_endpoint, zmq::buffer(endpoint)));
|
|
|
|
return endpoint;
|
|
|
|
}
|
2018-05-11 11:43:41 +02:00
|
|
|
|
|
|
|
struct common_server_client_setup
|
|
|
|
{
|
2018-07-05 00:46:47 +02:00
|
|
|
common_server_client_setup(bool initialize = true)
|
|
|
|
{
|
|
|
|
if (initialize)
|
|
|
|
init();
|
|
|
|
}
|
2018-05-11 11:43:41 +02:00
|
|
|
|
|
|
|
void init()
|
|
|
|
{
|
2020-03-24 09:33:50 +01:00
|
|
|
endpoint = bind_ip4_loopback(server);
|
2018-09-23 18:14:25 +02:00
|
|
|
REQUIRE_NOTHROW(client.connect(endpoint));
|
2018-05-11 11:43:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
zmq::context_t context;
|
2018-07-05 00:46:47 +02:00
|
|
|
zmq::socket_t server{context, zmq::socket_type::pair};
|
|
|
|
zmq::socket_t client{context, zmq::socket_type::pair};
|
2018-05-11 11:43:41 +02:00
|
|
|
std::string endpoint;
|
|
|
|
};
|
|
|
|
#endif
|