summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2012-02-16 10:04:25 +0900
committerMartin Sustrik <sustrik@250bpm.com>2012-02-16 10:04:25 +0900
commit746cabf4868ff4b9bf46e01a16b43943c8e9454c (patch)
tree166ef9b64c84f4a7df775db002d526cd97a4bd69
parente4f9075273c2785f4d2a4416b92cefa9e9cc9bbc (diff)
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 <sustrik@250bpm.com>
-rw-r--r--src/dist.cpp7
1 files changed, 5 insertions, 2 deletions
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);