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:
Doron Somech
2020-04-17 13:20:57 +03:00
parent 4c1d720a47
commit 81444136d5
18 changed files with 224 additions and 9 deletions

View File

@@ -442,15 +442,26 @@ void zmq::session_base_t::process_attach (i_engine *engine_)
_engine->plug (_io_thread, this);
}
void zmq::session_base_t::engine_error (zmq::i_engine::error_reason_t reason_)
void zmq::session_base_t::engine_error (bool handshaked_,
zmq::i_engine::error_reason_t reason_)
{
// Engine is dead. Let's forget about it.
_engine = NULL;
// Remove any half-done messages from the pipes.
if (_pipe)
if (_pipe) {
clean_pipes ();
#ifdef ZMQ_BUILD_DRAFT_API
// Only send disconnect message if socket was accepted and handshake was completed
if (!_active && handshaked_ && options.can_recv_disconnect_msg
&& !options.disconnect_msg.empty ()) {
_pipe->set_disconnect_msg (options.disconnect_msg);
_pipe->send_disconnect_msg ();
}
#endif
}
zmq_assert (reason_ == i_engine::connection_error
|| reason_ == i_engine::timeout_error
|| reason_ == i_engine::protocol_error);