From 87f2dff38c0890d1f7efe5514b57cb03b29b740f Mon Sep 17 00:00:00 2001 From: Pieter Hintjens Date: Fri, 11 Sep 2015 13:15:00 -0400 Subject: [PATCH] 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. --- include/zmq.h | 4 ++-- src/msg.cpp | 6 +++--- src/msg.hpp | 4 ++-- src/pipe.hpp | 4 ++-- src/server.cpp | 6 +++--- src/zmq.cpp | 8 ++++---- tests/test_client_server.cpp | 18 ++++++++---------- 7 files changed, 24 insertions(+), 26 deletions(-) diff --git a/include/zmq.h b/include/zmq.h index f797b4c6..62479163 100644 --- a/include/zmq.h +++ b/include/zmq.h @@ -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); /******************************************************************************/ diff --git a/src/msg.cpp b/src/msg.cpp index 47fe7a25..edf0910d 100644 --- a/src/msg.cpp +++ b/src/msg.cpp @@ -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) { diff --git a/src/msg.hpp b/src/msg.hpp index 1090038f..c60bc955 100644 --- a/src/msg.hpp +++ b/src/msg.hpp @@ -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. diff --git a/src/pipe.hpp b/src/pipe.hpp index b795f641..ae85b32c 100644 --- a/src/pipe.hpp +++ b/src/pipe.hpp @@ -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_); diff --git a/src/server.cpp b/src/server.cpp index 52bd256e..7fb37801 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -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; } diff --git a/src/zmq.cpp b/src/zmq.cpp index 1a7da781..cd4a3962 100644 --- a/src/zmq.cpp +++ b/src/zmq.cpp @@ -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_)); diff --git a/tests/test_client_server.cpp b/tests/test_client_server.cpp index 155232ea..2d6b6e0a 100644 --- a/tests/test_client_server.cpp +++ b/tests/test_client_server.cpp @@ -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);