mirror of
https://github.com/zeromq/libzmq.git
synced 2025-10-30 05:29:43 +01:00
Define i_properties interface
- copy and move message operations are updated to maintain proper reference count of properties object - zmq_msg_gets updated to use i_properties interface to fetch property value - setter/getter added to msg_t class
This commit is contained in:
28
src/msg.cpp
28
src/msg.cpp
@@ -26,6 +26,7 @@
|
||||
|
||||
#include "stdint.hpp"
|
||||
#include "likely.hpp"
|
||||
#include "i_properties.hpp"
|
||||
#include "err.hpp"
|
||||
|
||||
// Check whether the sizes of public representation of the message (zmq_msg_t)
|
||||
@@ -149,11 +150,14 @@ int zmq::msg_t::close ()
|
||||
}
|
||||
}
|
||||
|
||||
if (u.base.properties != NULL)
|
||||
if (u.base.properties->drop_ref ())
|
||||
delete u.base.properties;
|
||||
|
||||
// Make the message invalid.
|
||||
u.base.type = 0;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int zmq::msg_t::move (msg_t &src_)
|
||||
@@ -201,6 +205,9 @@ int zmq::msg_t::copy (msg_t &src_)
|
||||
}
|
||||
}
|
||||
|
||||
if (src_.u.base.properties != NULL)
|
||||
src_.u.base.properties->add_ref ();
|
||||
|
||||
*this = src_;
|
||||
|
||||
return 0;
|
||||
@@ -268,6 +275,19 @@ void zmq::msg_t::set_fd (int64_t fd_)
|
||||
file_desc = fd_;
|
||||
}
|
||||
|
||||
zmq::i_properties *zmq::msg_t::properties () const
|
||||
{
|
||||
return u.base.properties;
|
||||
}
|
||||
|
||||
void zmq::msg_t::set_properties (zmq::i_properties *properties_)
|
||||
{
|
||||
assert (properties_ != NULL);
|
||||
assert (u.base.properties == NULL);
|
||||
properties_->add_ref ();
|
||||
u.base.properties = properties_;
|
||||
}
|
||||
|
||||
bool zmq::msg_t::is_identity () const
|
||||
{
|
||||
return (u.base.flags & identity) == identity;
|
||||
@@ -297,6 +317,9 @@ void zmq::msg_t::add_refs (int refs_)
|
||||
{
|
||||
zmq_assert (refs_ >= 0);
|
||||
|
||||
// Operation not supported for messages with properties.
|
||||
zmq_assert (u.base.properties == NULL);
|
||||
|
||||
// No copies required.
|
||||
if (!refs_)
|
||||
return;
|
||||
@@ -317,6 +340,9 @@ bool zmq::msg_t::rm_refs (int refs_)
|
||||
{
|
||||
zmq_assert (refs_ >= 0);
|
||||
|
||||
// Operation not supported for messages with properties.
|
||||
zmq_assert (u.base.properties == NULL);
|
||||
|
||||
// No copies required.
|
||||
if (!refs_)
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user