diff options
author | Martin Sustrik <sustrik@250bpm.com> | 2011-04-21 22:27:48 +0200 |
---|---|---|
committer | Martin Sustrik <sustrik@250bpm.com> | 2011-04-21 22:27:48 +0200 |
commit | e0246e32d79d71f8e73207b43aed8b23648e4fc7 (patch) | |
tree | 9952ee6fd39f4e27bbe932f6b6f30f0073009369 /src/rep.cpp | |
parent | 581697695aac72894f2d3fefac904b9d50b3ba67 (diff) |
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 <sustrik@250bpm.com>
Diffstat (limited to 'src/rep.cpp')
-rw-r--r-- | src/rep.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/rep.cpp b/src/rep.cpp index 46c35cb..ef0defc 100644 --- a/src/rep.cpp +++ b/src/rep.cpp @@ -18,10 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "../include/zmq.h" - #include "rep.hpp" #include "err.hpp" +#include "msg.hpp" zmq::rep_t::rep_t (class ctx_t *parent_, uint32_t tid_) : xrep_t (parent_, tid_), @@ -35,7 +34,7 @@ zmq::rep_t::~rep_t () { } -int zmq::rep_t::xsend (zmq_msg_t *msg_, int flags_) +int zmq::rep_t::xsend (msg_t *msg_, int flags_) { // If we are in the middle of receiving a request, we cannot send reply. if (!sending_reply) { @@ -43,7 +42,7 @@ int zmq::rep_t::xsend (zmq_msg_t *msg_, int flags_) return -1; } - bool more = (msg_->flags & ZMQ_MSG_MORE); + bool more = (msg_->flags () & msg_t::more); // Push message to the reply pipe. int rc = xrep_t::xsend (msg_, flags_); @@ -57,7 +56,7 @@ int zmq::rep_t::xsend (zmq_msg_t *msg_, int flags_) return 0; } -int zmq::rep_t::xrecv (zmq_msg_t *msg_, int flags_) +int zmq::rep_t::xrecv (msg_t *msg_, int flags_) { // If we are in middle of sending a reply, we cannot receive next request. if (sending_reply) { @@ -78,10 +77,10 @@ int zmq::rep_t::xrecv (zmq_msg_t *msg_, int flags_) int rc = xrep_t::xrecv (msg_, flags_); if (rc != 0) return rc; - zmq_assert (msg_->flags & ZMQ_MSG_MORE); + zmq_assert (msg_->flags () & msg_t::more); // Empty message part delimits the traceback stack. - bottom = (zmq_msg_size (msg_) == 0); + bottom = (msg_->size () == 0); // Push it to the reply pipe. rc = xrep_t::xsend (msg_, flags_); @@ -98,7 +97,7 @@ int zmq::rep_t::xrecv (zmq_msg_t *msg_, int flags_) return rc; // If whole request is read, flip the FSM to reply-sending state. - if (!(msg_->flags & ZMQ_MSG_MORE)) { + if (!(msg_->flags () & msg_t::more)) { sending_reply = true; request_begins = true; } |