From d4374cbebef4e75ec2805099b9f69a7c7d69ecba Mon Sep 17 00:00:00 2001 From: Joseph Artsimovich Date: Sat, 19 May 2018 08:44:41 +0300 Subject: [PATCH] Add message_t::routing_id() and set_routing_id() Setting a routing id is necessary when sending a message through a ZMQ_SERVER socket. See [1] for more details. [1] http://api.zeromq.org/4-2:zmq-socket#toc5 --- tests/message.cpp | 9 +++++++++ zmq.hpp | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/tests/message.cpp b/tests/message.cpp index 22896c1..014ac3c 100644 --- a/tests/message.cpp +++ b/tests/message.cpp @@ -118,3 +118,12 @@ TEST(message, equality_non_equal_lhs_empty) const zmq::message_t msg_b("Hi", 2); ASSERT_NE(msg_a, msg_b); } + +#if defined(ZMQ_BUILD_DRAFT_API) && ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 2, 0) +TEST(message, routing_id_persists) +{ + zmq::message_t msg; + msg.set_routing_id(123); + ASSERT_EQ(123u, msg.routing_id()); +} +#endif diff --git a/zmq.hpp b/zmq.hpp index ef6cc78..8f597bf 100644 --- a/zmq.hpp +++ b/zmq.hpp @@ -396,6 +396,21 @@ class message_t return value; } #endif + +#if defined(ZMQ_BUILD_DRAFT_API) && ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 2, 0) + inline uint32_t routing_id() const + { + return zmq_msg_routing_id(const_cast(&msg)); + } + + inline void set_routing_id(uint32_t routing_id) + { + int rc = zmq_msg_set_routing_id(&msg, routing_id); + if (rc != 0) + throw error_t(); + } +#endif + /** Dump content to string. Ascii chars are readable, the rest is printed as hex. * Probably ridiculously slow. */