Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions tests/socket.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include <catch.hpp>
#include <zmq.hpp>
#ifdef ZMQ_CPP11
#include <future>
#endif

TEST_CASE("socket create destroy", "[socket]")
{
Expand Down Expand Up @@ -27,3 +30,59 @@ TEST_CASE("socket sends and receives const buffer", "[socket]")
CHECK(2 == receiver.recv(buf, 2));
CHECK(0 == memcmp(buf, "Hi", 2));
}

#ifdef ZMQ_CPP11
TEST_CASE("socket proxy", "[socket]")
{
zmq::context_t context;
zmq::socket_t front(context, ZMQ_ROUTER);
zmq::socket_t back(context, ZMQ_ROUTER);
zmq::socket_t capture(context, ZMQ_DEALER);
front.bind("inproc://test1");
back.bind("inproc://test2");
capture.bind("inproc://test3");
auto f = std::async(std::launch::async, [&]() {
auto s1 = std::move(front);
auto s2 = std::move(back);
auto s3 = std::move(capture);
try
{
zmq::proxy(s1, s2, &s3);
}
catch (const zmq::error_t& e)
{
return e.num() == ETERM;
}
return false;
});
context.close();
CHECK(f.get());
}

TEST_CASE("socket proxy steerable", "[socket]")
{
zmq::context_t context;
zmq::socket_t front(context, ZMQ_ROUTER);
zmq::socket_t back(context, ZMQ_ROUTER);
zmq::socket_t control(context, ZMQ_SUB);
front.bind("inproc://test1");
back.bind("inproc://test2");
control.connect("inproc://test3");
auto f = std::async(std::launch::async, [&]() {
auto s1 = std::move(front);
auto s2 = std::move(back);
auto s3 = std::move(control);
try
{
zmq::proxy_steerable(s1, s2, ZMQ_NULLPTR, &s3);
}
catch (const zmq::error_t& e)
{
return e.num() == ETERM;
}
return false;
});
context.close();
CHECK(f.get());
}
#endif
56 changes: 39 additions & 17 deletions zmq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,23 +201,6 @@ inline int poll(std::vector<zmq_pollitem_t> &items, long timeout_ = -1)
#endif


inline void proxy(void *frontend, void *backend, void *capture)
{
int rc = zmq_proxy(frontend, backend, capture);
if (rc != 0)
throw error_t();
}

#ifdef ZMQ_HAS_PROXY_STEERABLE
inline void
proxy_steerable(void *frontend, void *backend, void *capture, void *control)
{
int rc = zmq_proxy_steerable(frontend, backend, capture, control);
if (rc != 0)
throw error_t();
}
#endif

inline void version(int *major_, int *minor_, int *patch_)
{
zmq_version(major_, minor_, patch_);
Expand Down Expand Up @@ -792,6 +775,45 @@ class socket_t
void operator=(const socket_t &) ZMQ_DELETED_FUNCTION;
};

ZMQ_DEPRECATED("from 4.3.1, use proxy taking socket_t objects")
inline void proxy(void *frontend, void *backend, void *capture)
{
int rc = zmq_proxy(frontend, backend, capture);
if (rc != 0)
throw error_t();
}

inline void proxy(socket_t &frontend, socket_t &backend, socket_t *capture = ZMQ_NULLPTR)
{
int rc = zmq_proxy(static_cast<void *>(frontend),
static_cast<void *>(backend),
capture ? static_cast<void *>(*capture) : ZMQ_NULLPTR);
if (rc != 0)
throw error_t();
}

#ifdef ZMQ_HAS_PROXY_STEERABLE
ZMQ_DEPRECATED("from 4.3.1, use proxy_steerable taking socket_t objects")
inline void
proxy_steerable(void *frontend, void *backend, void *capture, void *control)
{
int rc = zmq_proxy_steerable(frontend, backend, capture, control);
if (rc != 0)
throw error_t();
}

inline void
proxy_steerable(socket_t &frontend, socket_t &backend, socket_t *capture, socket_t *control)
{
int rc = zmq_proxy_steerable(static_cast<void *>(frontend),
static_cast<void *>(backend),
capture ? static_cast<void *>(*capture) : ZMQ_NULLPTR,
control ? static_cast<void *>(*control) : ZMQ_NULLPTR);
if (rc != 0)
throw error_t();
}
#endif

class monitor_t
{
public:
Expand Down