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/req.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'src/req.cpp') diff --git a/src/req.cpp b/src/req.cpp index 503f221..6bf502f 100644 --- a/src/req.cpp +++ b/src/req.cpp @@ -18,10 +18,9 @@ along with this program. If not, see . */ -#include "../include/zmq.h" - #include "req.hpp" #include "err.hpp" +#include "msg.hpp" zmq::req_t::req_t (class ctx_t *parent_, uint32_t tid_) : xreq_t (parent_, tid_), @@ -35,7 +34,7 @@ zmq::req_t::~req_t () { } -int zmq::req_t::xsend (zmq_msg_t *msg_, int flags_) +int zmq::req_t::xsend (msg_t *msg_, int flags_) { // If we've sent a request and we still haven't got the reply, // we can't send another request. @@ -46,17 +45,17 @@ int zmq::req_t::xsend (zmq_msg_t *msg_, int flags_) // First part of the request is empty message part (stack bottom). if (message_begins) { - zmq_msg_t prefix; - int rc = zmq_msg_init (&prefix); - zmq_assert (rc == 0); - prefix.flags |= ZMQ_MSG_MORE; + msg_t prefix; + int rc = prefix.init (); + errno_assert (rc == 0); + prefix.set_flags (msg_t::more); rc = xreq_t::xsend (&prefix, flags_); if (rc != 0) return rc; message_begins = false; } - bool more = msg_->flags & ZMQ_MSG_MORE; + bool more = msg_->flags () & msg_t::more; int rc = xreq_t::xsend (msg_, flags_); if (rc != 0) @@ -71,7 +70,7 @@ int zmq::req_t::xsend (zmq_msg_t *msg_, int flags_) return 0; } -int zmq::req_t::xrecv (zmq_msg_t *msg_, int flags_) +int zmq::req_t::xrecv (msg_t *msg_, int flags_) { // If request wasn't send, we can't wait for reply. if (!receiving_reply) { @@ -84,8 +83,8 @@ int zmq::req_t::xrecv (zmq_msg_t *msg_, int flags_) int rc = xreq_t::xrecv (msg_, flags_); if (rc != 0) return rc; - zmq_assert (msg_->flags & ZMQ_MSG_MORE); - zmq_assert (zmq_msg_size (msg_) == 0); + zmq_assert (msg_->flags () & msg_t::more); + zmq_assert (msg_->size () == 0); message_begins = false; } @@ -94,7 +93,7 @@ int zmq::req_t::xrecv (zmq_msg_t *msg_, int flags_) return rc; // If the reply is fully received, flip the FSM into request-sending state. - if (!(msg_->flags & ZMQ_MSG_MORE)) { + if (!(msg_->flags () & msg_t::more)) { receiving_reply = false; message_begins = true; } -- cgit v1.2.3