0
0
mirror of https://github.com/zeromq/libzmq.git synced 2024-12-27 15:41:05 +08:00

Problem: zmq_msg_get_routing_id () is not consistent with API

We do not use 'get' for getters.

Solution: rename to zmq_msg_routing_id () for public API.
This commit is contained in:
Pieter Hintjens 2015-09-11 13:15:00 -04:00
parent 7be6ad0504
commit 87f2dff38c
7 changed files with 24 additions and 26 deletions

View File

@ -227,8 +227,8 @@ ZMQ_EXPORT int zmq_msg_more (zmq_msg_t *msg);
ZMQ_EXPORT int zmq_msg_get (zmq_msg_t *msg, int property);
ZMQ_EXPORT int zmq_msg_set (zmq_msg_t *msg, int property, int optval);
ZMQ_EXPORT const char *zmq_msg_gets (zmq_msg_t *msg, const char *property);
ZMQ_EXPORT int zmq_msg_set_routing_id(zmq_msg_t *msg, uint32_t routing_id);
ZMQ_EXPORT uint32_t zmq_msg_get_routing_id(zmq_msg_t *msg);
ZMQ_EXPORT int zmq_msg_set_routing_id (zmq_msg_t *msg, uint32_t routing_id);
ZMQ_EXPORT uint32_t zmq_msg_routing_id (zmq_msg_t *msg);
/******************************************************************************/

View File

@ -497,18 +497,18 @@ bool zmq::msg_t::rm_refs (int refs_)
return true;
}
uint32_t zmq::msg_t::get_routing_id()
uint32_t zmq::msg_t::get_routing_id ()
{
return u.base.routing_id;
}
int zmq::msg_t::set_routing_id(uint32_t routing_id_)
int zmq::msg_t::set_routing_id (uint32_t routing_id_)
{
u.base.routing_id = routing_id_;
return 0;
}
zmq::atomic_counter_t* zmq::msg_t::refcnt()
zmq::atomic_counter_t *zmq::msg_t::refcnt()
{
switch(u.base.type)
{

View File

@ -97,8 +97,8 @@ namespace zmq
bool is_vsm () const;
bool is_cmsg () const;
bool is_zcmsg() const;
uint32_t get_routing_id();
int set_routing_id(uint32_t routing_id_);
uint32_t get_routing_id ();
int set_routing_id (uint32_t routing_id_);
// After calling this function you can copy the message in POD-style
// refs_ times. No need to call copy.

View File

@ -85,8 +85,8 @@ namespace zmq
void set_event_sink (i_pipe_events *sink_);
// Pipe endpoint can store an routing ID to be used by its clients.
void set_routing_id(uint32_t routing_id_);
uint32_t get_routing_id();
void set_routing_id (uint32_t routing_id_);
uint32_t get_routing_id ();
// Pipe endpoint can store an opaque ID to be used by its clients.
void set_identity (const blob_t &identity_);

View File

@ -93,7 +93,7 @@ int zmq::server_t::xsend (msg_t *msg_)
zmq_assert(!(msg_->flags () & msg_t::more));
// Find the pipe associated with the routing stored in the message.
uint32_t routing_id = msg_->get_routing_id();
uint32_t routing_id = msg_->get_routing_id ();
outpipes_t::iterator it = outpipes.find (routing_id);
if (it != outpipes.end ()) {
@ -148,8 +148,8 @@ int zmq::server_t::xrecv (msg_t *msg_)
zmq_assert (pipe != NULL);
uint32_t routing_id = pipe->get_routing_id();
msg_->set_routing_id(routing_id);
uint32_t routing_id = pipe->get_routing_id ();
msg_->set_routing_id (routing_id);
return 0;
}

View File

@ -686,19 +686,19 @@ int zmq_msg_set (zmq_msg_t *, int, int)
int zmq_msg_set_routing_id (zmq_msg_t *msg_, uint32_t routing_id_)
{
return ((zmq::msg_t*) msg_)->set_routing_id(routing_id_);
return ((zmq::msg_t *) msg_)->set_routing_id (routing_id_);
}
uint32_t zmq_msg_get_routing_id(zmq_msg_t *msg_)
uint32_t zmq_msg_routing_id (zmq_msg_t *msg_)
{
return ((zmq::msg_t*) msg_)->get_routing_id();
return ((zmq::msg_t *) msg_)->get_routing_id ();
}
// Get message metadata string
const char *zmq_msg_gets (zmq_msg_t *msg_, const char *property_)
{
zmq::metadata_t *metadata = ((zmq::msg_t*) msg_)->metadata ();
zmq::metadata_t *metadata = ((zmq::msg_t *) msg_)->metadata ();
const char *value = NULL;
if (metadata)
value = metadata->get (std::string (property_));

View File

@ -38,31 +38,29 @@ int main (void)
void *server = zmq_socket (ctx, ZMQ_SERVER);
void *client = zmq_socket (ctx, ZMQ_CLIENT);
int rc;
rc = zmq_bind (server, "tcp://127.0.0.1:5560");
int rc = zmq_bind (server, "tcp://127.0.0.1:5560");
assert (rc == 0);
rc = zmq_connect (client, "tcp://127.0.0.1:5560");
assert (rc == 0);
zmq_msg_t msg;
rc = zmq_msg_init_size(&msg,1);
rc = zmq_msg_init_size (&msg, 1);
assert (rc == 0);
char * data = (char *)zmq_msg_data(&msg);
data[0] = 1;
char *data = (char *) zmq_msg_data (&msg);
data [0] = 1;
rc = zmq_msg_send(&msg, client, 0);
assert (rc == 1);
rc = zmq_msg_init(&msg);
rc = zmq_msg_init (&msg);
assert (rc == 0);
rc = zmq_msg_recv(&msg, server, 0);
rc = zmq_msg_recv (&msg, server, 0);
assert (rc == 1);
uint32_t routing_id = zmq_msg_get_routing_id(&msg);
assert(routing_id != 0);
uint32_t routing_id = zmq_msg_routing_id (&msg);
assert (routing_id != 0);
rc = zmq_msg_close(&msg);
assert (rc == 0);