Adds support for detecting ZMQ_STREAM disconnections.

When a ZMQ_STREAM socket connection is broken (intentionally, via `shutdown()`
or accidentally via client crash or network failure), there is no way for the
application to dertermine that it should drop per-connection data (such as
buffers).

This contribution makes sure the application receives a 0-length message to
notify it that the connection has been broken.  This is symmetric with the
process of closing the connection from within the application (where the
application sends a 0-length message to tell ZeroMQ to close the connection).

Conflicts:
	CMakeLists.txt
This commit is contained in:
Andre Caron
2014-01-12 22:36:47 -05:00
parent f253fe5f42
commit 17651b9276
6 changed files with 215 additions and 1 deletions

View File

@@ -780,6 +780,14 @@ int zmq::stream_engine_t::write_subscription_msg (msg_t *msg_)
void zmq::stream_engine_t::error ()
{
if (options.raw_sock) {
// For raw sockets, send a final 0-length message to the application
// so that it knows the peer has been disconnected.
msg_t terminator;
terminator.init();
(this->*write_msg) (&terminator);
terminator.close();
}
zmq_assert (session);
socket->event_disconnected (endpoint, s);
session->flush ();