summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2012-04-27 10:29:37 +0200
committerMartin Sustrik <sustrik@250bpm.com>2012-04-27 10:29:37 +0200
commit2602a776e520ff12769cac152559b0bf33d5f70f (patch)
treef054a5b337ac53207cab266b86cf77e69e675b52
parent9024634047db64355edca803d6146b233bdff00f (diff)
Truncate the message when it is sent to XSUB
This patch is based on patch by Martin Hurton from 0MQ project. Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
-rw-r--r--src/xsub.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/xsub.cpp b/src/xsub.cpp
index 3afd734..7272a8e 100644
--- a/src/xsub.cpp
+++ b/src/xsub.cpp
@@ -117,24 +117,25 @@ int xs::xsub_t::xsend (msg_t *msg_, int flags_)
++it->second;
if (it->second == 1)
return dist.send_to_all (msg_, flags_);
- else
- return 0;
}
else if (cmd == XS_CMD_UNSUBSCRIBE) {
subscriptions_t::iterator it = subscriptions.find (
std::make_pair (filter_id, blob_t (data + 4, size - 4)));
- if (it == subscriptions.end ())
- return 0;
- xs_assert (it->second);
- --it->second;
- if (it->second)
- return 0;
- subscriptions.erase (it);
- return dist.send_to_all (msg_, flags_);
+ if (it != subscriptions.end ()) {
+ xs_assert (it->second);
+ --it->second;
+ if (!it->second) {
+ subscriptions.erase (it);
+ return dist.send_to_all (msg_, flags_);
+ }
+ }
}
- xs_assert (false);
- return -1;
+ int rc = msg_->close ();
+ errno_assert (rc == 0);
+ rc = msg_->init ();
+ errno_assert (rc == 0);
+ return 0;
}
bool xs::xsub_t::xhas_out ()