diff --git a/include/zmq.h b/include/zmq.h index 16448c36..247114c9 100644 --- a/include/zmq.h +++ b/include/zmq.h @@ -274,6 +274,7 @@ ZMQ_EXPORT int zmq_msg_set (zmq_msg_t *msg, int option, int optval); #define ZMQ_CURVE_SERVER 47 #define ZMQ_CURVE_PUBLICKEY 48 #define ZMQ_CURVE_SERVERKEY 49 +#define ZMQ_ROUTER_ANNOUNCE_SELF 50 /* Message options */ #define ZMQ_MORE 1 diff --git a/src/router.cpp b/src/router.cpp index c008e5d6..d6eb0fb9 100644 --- a/src/router.cpp +++ b/src/router.cpp @@ -33,7 +33,8 @@ zmq::router_t::router_t (class ctx_t *parent_, uint32_t tid_, int sid_) : more_out (false), next_peer_id (generate_random ()), mandatory(false), - raw_sock(false) + raw_sock(false), + announce_self(false) { options.type = ZMQ_ROUTER; options.recv_identity = true; @@ -94,6 +95,13 @@ int zmq::router_t::xsetsockopt (int option_, const void *optval_, printf ("E: invalid option value (int=%d value=%d)\n", is_int, value); break; + case ZMQ_ROUTER_ANNOUNCE_SELF: + if (is_int && value >= 0) { + announce_self = value; + return 0; + } + break; + default: break; } @@ -389,6 +397,15 @@ bool zmq::router_t::identify_peer (pipe_t *pipe_) ok = outpipes.insert (outpipes_t::value_type (identity, outpipe)).second; zmq_assert (ok); + if (announce_self) { + msg_t tmp_; + tmp_.init (); + ok = pipe_->write (&tmp_); + zmq_assert (ok); + pipe_->flush (); + tmp_.close (); + }; + return true; } diff --git a/src/router.hpp b/src/router.hpp index 37ae5e25..426858e9 100644 --- a/src/router.hpp +++ b/src/router.hpp @@ -112,6 +112,9 @@ namespace zmq bool mandatory; bool raw_sock; + // if true, send an empty message to every connected peer to solve 'who will write first' race condition + bool announce_self; + router_t (const router_t&); const router_t &operator = (const router_t&); };