Skip to content

Commit d4374cb

Browse files
committed
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
1 parent b11e445 commit d4374cb

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

tests/message.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,12 @@ TEST(message, equality_non_equal_lhs_empty)
118118
const zmq::message_t msg_b("Hi", 2);
119119
ASSERT_NE(msg_a, msg_b);
120120
}
121+
122+
#if defined(ZMQ_BUILD_DRAFT_API) && ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 2, 0)
123+
TEST(message, routing_id_persists)
124+
{
125+
zmq::message_t msg;
126+
msg.set_routing_id(123);
127+
ASSERT_EQ(123u, msg.routing_id());
128+
}
129+
#endif

zmq.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,21 @@ class message_t
396396
return value;
397397
}
398398
#endif
399+
400+
#if defined(ZMQ_BUILD_DRAFT_API) && ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 2, 0)
401+
inline uint32_t routing_id() const
402+
{
403+
return zmq_msg_routing_id(const_cast<zmq_msg_t*>(&msg));
404+
}
405+
406+
inline void set_routing_id(uint32_t routing_id)
407+
{
408+
int rc = zmq_msg_set_routing_id(&msg, routing_id);
409+
if (rc != 0)
410+
throw error_t();
411+
}
412+
#endif
413+
399414
/** Dump content to string. Ascii chars are readable, the rest is printed as hex.
400415
* Probably ridiculously slow.
401416
*/

0 commit comments

Comments
 (0)