Commit 8269b23e authored by Simon Giesecke's avatar Simon Giesecke

Problem: magic numbers and code duplication in msg.cpp

Solution: extract constants and unified cases
parent 18000a21
......@@ -299,27 +299,21 @@ int zmq::msg_t::copy (msg_t &src_)
if (unlikely (rc < 0))
return rc;
if (src_._u.base.type == type_lmsg) {
// One reference is added to shared messages. Non-shared messages
// are turned into shared messages and reference count is set to 2.
if (src_._u.lmsg.flags & msg_t::shared)
src_._u.lmsg.content->refcnt.add (1);
else {
src_._u.lmsg.flags |= msg_t::shared;
src_._u.lmsg.content->refcnt.set (2);
}
}
// The initial reference count, when a non-shared message is initially
// shared (between the original and the copy we create here).
const atomic_counter_t::integer_t initial_shared_refcnt = 2;
if (src_.is_zcmsg ()) {
if (src_.is_lmsg () || src_.is_zcmsg ()) {
// One reference is added to shared messages. Non-shared messages
// are turned into shared messages and reference count is set to 2.
if (src_._u.zclmsg.flags & msg_t::shared)
// are turned into shared messages.
if (src_.flags () & msg_t::shared)
src_.refcnt ()->add (1);
else {
src_._u.zclmsg.flags |= msg_t::shared;
src_.refcnt ()->set (2);
src_.set_flags (msg_t::shared);
src_.refcnt ()->set (initial_shared_refcnt);
}
}
if (src_._u.base.metadata != NULL)
src_._u.base.metadata->add_ref ();
......@@ -431,6 +425,11 @@ bool zmq::msg_t::is_cmsg () const
return _u.base.type == type_cmsg;
}
bool zmq::msg_t::is_lmsg () const
{
return _u.base.type == type_lmsg;
}
bool zmq::msg_t::is_zcmsg () const
{
return _u.base.type == type_zclmsg;
......
......@@ -117,6 +117,7 @@ class msg_t
bool is_leave () const;
bool is_vsm () const;
bool is_cmsg () const;
bool is_lmsg () const;
bool is_zcmsg () const;
uint32_t get_routing_id ();
int set_routing_id (uint32_t routing_id_);
......
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