Skip to content

Commit

Permalink
Add message_t::routing_id() and set_routing_id()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Tulon committed May 19, 2018
1 parent b11e445 commit d4374cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions zmq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<zmq_msg_t*>(&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.
*/
Expand Down

0 comments on commit d4374cb

Please sign in to comment.