From 2fe9dd9101af6f7e9641b187b59829f8828d5766 Mon Sep 17 00:00:00 2001 From: trya Date: Mon, 23 Sep 2019 01:15:23 +0200 Subject: [PATCH] Problem: ZMQ_CONFLATE on PUB sockets delivers to only one subscriber at most Solution: Fix behavior of dbuffer on writes. Message passed in argument of dbuffer::write can be assigned directly to the back buffer without leaking, since the message has already the right reference count (see dist::distribute and msg_t::add_refs). Secondly, in order to prevent the message pending in the front buffer from leaking if it hasn't been closed yet (for example because the peer is not reachable anymore), move back buffer to front buffer using msg_t::move instead of swapping the buffers, thus allowing release of the message in the front buffer. --- src/dbuffer.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dbuffer.hpp b/src/dbuffer.hpp index a1ef4990..52a7fa1c 100644 --- a/src/dbuffer.hpp +++ b/src/dbuffer.hpp @@ -78,12 +78,12 @@ template <> class dbuffer_t msg_t &xvalue = const_cast (value_); zmq_assert (xvalue.check ()); - _back->move (xvalue); // cannot just overwrite, might leak + *_back = value_; zmq_assert (_back->check ()); if (_sync.try_lock ()) { - std::swap (_back, _front); + _front->move (*_back); _has_msg = true; _sync.unlock ();