Skip to content

Commit 751f27d

Browse files
committed
Add support for RADIO/DISH sockets if draft API is enabled
This commit introduces new socket_type enumeration values as well as the following supporting functions: socket_t::join() socket_t::leave() message_t::group() message_t::set_group()
1 parent 73f171a commit 751f27d

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

tests/message.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,11 @@ TEST(message, routing_id_persists)
126126
msg.set_routing_id(123);
127127
ASSERT_EQ(123u, msg.routing_id());
128128
}
129+
130+
TEST(message, group_persists)
131+
{
132+
zmq::message_t msg;
133+
msg.set_group("mygroup");
134+
ASSERT_STREQ("mygroup", msg.group());
135+
}
129136
#endif

zmq.hpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,18 @@ class message_t
409409
if (rc != 0)
410410
throw error_t();
411411
}
412+
413+
inline const char* group() const
414+
{
415+
return zmq_msg_group(const_cast<zmq_msg_t*>(&msg));
416+
}
417+
418+
inline void set_group(const char* group)
419+
{
420+
int rc = zmq_msg_set_group(&msg, group);
421+
if (rc != 0)
422+
throw error_t();
423+
}
412424
#endif
413425

414426
/** Dump content to string. Ascii chars are readable, the rest is printed as hex.
@@ -546,9 +558,11 @@ enum class socket_type : int
546558
xsub = ZMQ_XSUB,
547559
push = ZMQ_PUSH,
548560
pull = ZMQ_PULL,
549-
#ifdef ZMQ_BUILD_DRAFT_API
561+
#if defined(ZMQ_BUILD_DRAFT_API) && ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 2, 0)
550562
server = ZMQ_SERVER,
551563
client = ZMQ_CLIENT,
564+
radio = ZMQ_RADIO,
565+
dish = ZMQ_DISH,
552566
#endif
553567
#if ZMQ_VERSION_MAJOR >= 4
554568
stream = ZMQ_STREAM,
@@ -715,6 +729,22 @@ class socket_t
715729
throw error_t();
716730
}
717731

732+
#if defined(ZMQ_BUILD_DRAFT_API) && ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 2, 0)
733+
inline void join(const char* group)
734+
{
735+
int rc = zmq_join(ptr, group);
736+
if (rc != 0)
737+
throw error_t();
738+
}
739+
740+
inline void leave(const char* group)
741+
{
742+
int rc = zmq_leave(ptr, group);
743+
if (rc != 0)
744+
throw error_t();
745+
}
746+
#endif
747+
718748
private:
719749
inline void init(context_t &context_, int type_)
720750
{

0 commit comments

Comments
 (0)