Commit 2910a728 authored by Martin Sustrik's avatar Martin Sustrik

msg_t::rm_refs closes the message when number of refs drops to 0 (issue 245)

Signed-off-by: 's avatarMartin Sustrik <sustrik@250bpm.com>
parent 82ab08d8
...@@ -257,17 +257,25 @@ void zmq::msg_t::add_refs (int refs_) ...@@ -257,17 +257,25 @@ void zmq::msg_t::add_refs (int refs_)
} }
} }
void zmq::msg_t::rm_refs (int refs_) bool zmq::msg_t::rm_refs (int refs_)
{ {
zmq_assert (refs_ >= 0); zmq_assert (refs_ >= 0);
// No copies required. // No copies required.
if (!refs_) if (!refs_)
return; return true;
// If there's only one reference close the message.
if (u.base.type != type_lmsg || !(u.lmsg.flags & msg_t::shared)) {
close ();
return false;
}
// The only message type that needs special care are long messages. // The only message type that needs special care are long messages.
if (u.base.type == type_lmsg) { if (!u.lmsg.content->refcnt.sub (refs_)) {
zmq_assert (u.lmsg.flags & msg_t::shared); close ();
u.lmsg.content->refcnt.sub (refs_); return false;
} }
return true;
} }
...@@ -73,8 +73,9 @@ namespace zmq ...@@ -73,8 +73,9 @@ namespace zmq
// refs_ times. No need to call copy. // refs_ times. No need to call copy.
void add_refs (int refs_); void add_refs (int refs_);
// Removes references previously added by add_refs. // Removes references previously added by add_refs. If the number of
void rm_refs (int refs_); // references drops to 0, the message is closed and false is returned.
bool rm_refs (int refs_);
private: private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment