Signed off and attached as requested.
From d76557e98fa176779f810856456222537e83641c Mon Sep 17 00:00:00 2001
From: Ben Gray <[email protected]>
Date: Thu, 27 Oct 2011 12:48:12 +0100
Subject: [PATCH] Patch for issue LIBZMQ-275. Dealing with VSM in distribution when pipes fail to write.

Signed-off-by: Ben Gray <[email protected]>
---
 src/dist.cpp |   15 +++++++++++++++
 src/msg.cpp  |    5 +++++
 src/msg.hpp  |    1 +
 3 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/src/dist.cpp b/src/dist.cpp
index 79baf43..1467b26 100644
--- a/src/dist.cpp
+++ b/src/dist.cpp
@@ -137,6 +137,21 @@ void zmq::dist_t::distribute (msg_t *msg_, int flags_)
         return;
     }
 
+    if (msg_->is_vsm()) {
+        // This can fail to write but in that case we drop and no clone would
+        // have been made
+        for (pipes_t::size_type i = 0; i < matching; ++i)
+            write (pipes [i], msg_);
+
+        int rc = msg_->close();
+        errno_assert (rc == 0);
+
+        rc = msg_->init ();
+        errno_assert (rc == 0);
+        return;
+    }
+
+
     //  Add matching-1 references to the message. We already hold one reference,
     //  that's why -1.
     msg_->add_refs ((int) matching - 1);
diff --git a/src/msg.cpp b/src/msg.cpp
index e51ab67..71ff294 100644
--- a/src/msg.cpp
+++ b/src/msg.cpp
@@ -237,6 +237,11 @@ bool zmq::msg_t::is_delimiter ()
     return u.base.type == type_delimiter;
 }
 
+bool zmq::msg_t::is_vsm ()
+{
+    return u.base.type == type_vsm;
+}
+
 void zmq::msg_t::add_refs (int refs_)
 {
     zmq_assert (refs_ >= 0);
diff --git a/src/msg.hpp b/src/msg.hpp
index 60495c8..ef6d9a3 100644
--- a/src/msg.hpp
+++ b/src/msg.hpp
@@ -67,6 +67,7 @@ namespace zmq
         void set_flags (unsigned char flags_);
         void reset_flags (unsigned char flags_);
         bool is_delimiter ();
+        bool is_vsm ();
 
         //  After calling this function you can copy the message in POD-style
         //  refs_ times. No need to call copy.
-- 
1.7.4.1

_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to