From e0246e32d79d71f8e73207b43aed8b23648e4fc7 Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Thu, 21 Apr 2011 22:27:48 +0200 Subject: Message-related functionality factored out into msg_t class. This patch addresses serveral issues: 1. It gathers message related functionality scattered over whole codebase into a single class. 2. It makes zmq_msg_t an opaque datatype. Internals of the class don't pollute zmq.h header file. 3. zmq_msg_t size decreases from 48 to 32 bytes. That saves ~33% of memory in scenarios with large amount of small messages. Signed-off-by: Martin Sustrik --- src/sub.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/sub.cpp') diff --git a/src/sub.cpp b/src/sub.cpp index aef7369..2d6ade6 100644 --- a/src/sub.cpp +++ b/src/sub.cpp @@ -18,9 +18,8 @@ along with this program. If not, see . */ -#include "../include/zmq.h" - #include "sub.hpp" +#include "msg.hpp" zmq::sub_t::sub_t (class ctx_t *parent_, uint32_t tid_) : xsub_t (parent_, tid_) @@ -41,9 +40,10 @@ int zmq::sub_t::xsetsockopt (int option_, const void *optval_, } // Create the subscription message. - zmq_msg_t msg; - zmq_msg_init_size (&msg, optvallen_ + 1); - unsigned char *data = (unsigned char*) zmq_msg_data (&msg); + msg_t msg; + int rc = msg.init_size (optvallen_ + 1); + errno_assert (rc == 0); + unsigned char *data = (unsigned char*) msg.data (); if (option_ == ZMQ_SUBSCRIBE) *data = 1; else if (option_ == ZMQ_UNSUBSCRIBE) @@ -52,16 +52,17 @@ int zmq::sub_t::xsetsockopt (int option_, const void *optval_, // Pass it further on in the stack. int err = 0; - int rc = xsub_t::xsend (&msg, 0); + rc = xsub_t::xsend (&msg, 0); if (rc != 0) err = errno; - zmq_msg_close (&msg); + int rc2 = msg.close (); + errno_assert (rc2 == 0); if (rc != 0) errno = err; return rc; } -int zmq::sub_t::xsend (zmq_msg_t *msg_, int options_) +int zmq::sub_t::xsend (msg_t *msg_, int options_) { // Overload the XSUB's send. errno = ENOTSUP; -- cgit v1.2.3