From 084e1c2193d73fe8db29603679e61f89907272ff Mon Sep 17 00:00:00 2001 From: Douglas Young Date: Sun, 25 Mar 2012 17:50:55 +0100 Subject: [PATCH] Fix for issue #307 dist was skipping over pipes when one failed because the non-working pipe got swapped with a working pipe but the write was never retried on that pipe --- src/dist.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/dist.cpp b/src/dist.cpp index d220c438..ccfa5c93 100644 --- a/src/dist.cpp +++ b/src/dist.cpp @@ -139,7 +139,8 @@ void zmq::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; // Retry last write because index will have been swapped int rc = msg_->close(); errno_assert (rc == 0); rc = msg_->init (); @@ -154,8 +155,10 @@ void zmq::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_)) { ++failed; + --i; // Retry last write because index will have been swapped + } if (unlikely (failed)) msg_->rm_refs (failed);