mirror of
https://github.com/zeromq/libzmq.git
synced 2025-10-29 20:59:47 +01:00
problem: router doesn't know when peer disconnected
ZMQ_ROUTER_NOTIFY doesn't have a context and doesn't play nice with protocols. with ZMQ_DISCONNECT_MSG we can set it to a protocol message, like DISCONNECT in majordomo. Router will send it when a peer is disconnected. Another advantage of ZMQ_DISCONNECT_MSG is that it also works on inproc. Together with ZMQ_HEARTBEAT it allows to build very reliable protocols, and much simpler as well.
This commit is contained in:
@@ -251,7 +251,9 @@ zmq::options_t::options_t () :
|
||||
monitor_event_version (1),
|
||||
wss_trust_system (false),
|
||||
hello_msg (),
|
||||
can_send_hello_msg (false)
|
||||
can_send_hello_msg (false),
|
||||
disconnect_msg (),
|
||||
can_recv_disconnect_msg (false)
|
||||
{
|
||||
memset (curve_public_key, 0, CURVE_KEYSIZE);
|
||||
memset (curve_secret_key, 0, CURVE_KEYSIZE);
|
||||
@@ -825,6 +827,16 @@ int zmq::options_t::setsockopt (int option_,
|
||||
hello_msg = std::vector<unsigned char> ();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
case ZMQ_DISCONNECT_MSG:
|
||||
if (optvallen_ > 0) {
|
||||
unsigned char *bytes = (unsigned char *) optval_;
|
||||
disconnect_msg =
|
||||
std::vector<unsigned char> (bytes, bytes + optvallen_);
|
||||
} else {
|
||||
disconnect_msg = std::vector<unsigned char> ();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user