From 746cabf4868ff4b9bf46e01a16b43943c8e9454c Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Thu, 16 Feb 2012 10:04:25 +0900 Subject: Message loss when a SUB socket disconnects fixed When there are multiple subscribers connected to the same PUB socket and one of them disconnects, one of the orhers loses one message. Fixed. Signed-off-by: Martin Sustrik --- src/dist.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/dist.cpp b/src/dist.cpp index 24f1132..f27564b 100644 --- a/src/dist.cpp +++ b/src/dist.cpp @@ -139,7 +139,8 @@ void xs::dist_t::distribute (msg_t *msg_, int flags_) if (msg_->is_vsm ()) { for (pipes_t::size_type i = 0; i < matching; ++i) - write (pipes [i], msg_); + if (!write (pipes [i], msg_)) + --i; int rc = msg_->close(); errno_assert (rc == 0); rc = msg_->init (); @@ -154,8 +155,10 @@ void xs::dist_t::distribute (msg_t *msg_, int flags_) // Push copy of the message to each matching pipe. int failed = 0; for (pipes_t::size_type i = 0; i < matching; ++i) - if (!write (pipes [i], msg_)) + if (!write (pipes [i], msg_)) { + --i; ++failed; + } if (unlikely (failed)) msg_->rm_refs (failed); -- cgit v1.2.3