mirror of
https://github.com/zeromq/libzmq.git
synced 2025-11-06 05:00:07 +01:00
Support application metadata through ZMQ_METADATA
Lets the application set per-connection metadata. Metadata is specified as "X-key:value" and set using zmq_setsockopt, eg: zmq_setsockopt (s, ZMQ_METADATA, "X-key:value", 11); The peer can then obtain the metadata from a received message: char *data = zmq_msg_gets(msg, "X-key");
This commit is contained in:
@@ -170,13 +170,30 @@ size_t zmq::mechanism_t::add_basic_properties (unsigned char *buf,
|
||||
options.routing_id, options.routing_id_size);
|
||||
}
|
||||
|
||||
|
||||
for (std::map<std::string, std::string>::const_iterator it =
|
||||
options.app_metadata.begin ();
|
||||
it != options.app_metadata.end (); ++it)
|
||||
ptr +=
|
||||
add_property (ptr, buf_capacity - (ptr - buf), it->first.c_str (),
|
||||
it->second.c_str (), strlen (it->second.c_str ()));
|
||||
|
||||
return ptr - buf;
|
||||
}
|
||||
|
||||
size_t zmq::mechanism_t::basic_properties_len () const
|
||||
{
|
||||
const char *socket_type = socket_type_string (options.type);
|
||||
int meta_len = 0;
|
||||
|
||||
for (std::map<std::string, std::string>::const_iterator it =
|
||||
options.app_metadata.begin ();
|
||||
it != options.app_metadata.end (); ++it)
|
||||
meta_len +=
|
||||
property_len (it->first.c_str (), strlen (it->second.c_str ()));
|
||||
|
||||
return property_len (ZMTP_PROPERTY_SOCKET_TYPE, strlen (socket_type))
|
||||
+ meta_len
|
||||
+ ((options.type == ZMQ_REQ || options.type == ZMQ_DEALER
|
||||
|| options.type == ZMQ_ROUTER)
|
||||
? property_len (ZMTP_PROPERTY_IDENTITY, options.routing_id_size)
|
||||
|
||||
Reference in New Issue
Block a user