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/socket_base.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/socket_base.cpp')
-rw-r--r-- | src/socket_base.cpp | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/src/socket_base.cpp b/src/socket_base.cpp index 9f3b1f6..d8af516 100644 --- a/src/socket_base.cpp +++ b/src/socket_base.cpp @@ -22,8 +22,6 @@ #include <string> #include <algorithm> -#include "../include/zmq.h" - #include "platform.hpp" #if defined ZMQ_HAVE_WINDOWS @@ -48,6 +46,7 @@ #include "platform.hpp" #include "likely.hpp" #include "uuid.hpp" +#include "msg.hpp" #include "pair.hpp" #include "pub.hpp" @@ -464,7 +463,7 @@ int zmq::socket_base_t::connect (const char *addr_) return 0; } -int zmq::socket_base_t::send (::zmq_msg_t *msg_, int flags_) +int zmq::socket_base_t::send (msg_t *msg_, int flags_) { // Check whether the library haven't been shut down yet. if (unlikely (ctx_terminated)) { @@ -473,7 +472,7 @@ int zmq::socket_base_t::send (::zmq_msg_t *msg_, int flags_) } // Check whether message passed to the function is valid. - if (unlikely ((msg_->flags | ZMQ_MSG_MASK) != 0xff)) { + if (unlikely (!msg_->check ())) { errno = EFAULT; return -1; } @@ -485,7 +484,7 @@ int zmq::socket_base_t::send (::zmq_msg_t *msg_, int flags_) // At this point we impose the MORE flag on the message. if (flags_ & ZMQ_SNDMORE) - msg_->flags |= ZMQ_MSG_MORE; + msg_->set_flags (msg_t::more); // Try to send the message. rc = xsend (msg_, flags_); @@ -509,7 +508,7 @@ int zmq::socket_base_t::send (::zmq_msg_t *msg_, int flags_) return 0; } -int zmq::socket_base_t::recv (::zmq_msg_t *msg_, int flags_) +int zmq::socket_base_t::recv (msg_t *msg_, int flags_) { // Check whether the library haven't been shut down yet. if (unlikely (ctx_terminated)) { @@ -518,7 +517,7 @@ int zmq::socket_base_t::recv (::zmq_msg_t *msg_, int flags_) } // Check whether message passed to the function is valid. - if (unlikely ((msg_->flags | ZMQ_MSG_MASK) != 0xff)) { + if (unlikely (!msg_->check ())) { errno = EFAULT; return -1; } @@ -543,9 +542,9 @@ int zmq::socket_base_t::recv (::zmq_msg_t *msg_, int flags_) // If we have the message, return immediately. if (rc == 0) { - rcvmore = msg_->flags & ZMQ_MSG_MORE; + rcvmore = msg_->flags () & msg_t::more; if (rcvmore) - msg_->flags &= ~ZMQ_MSG_MORE; + msg_->reset_flags (msg_t::more); return 0; } @@ -565,9 +564,9 @@ int zmq::socket_base_t::recv (::zmq_msg_t *msg_, int flags_) rc = xrecv (msg_, flags_); if (rc == 0) { - rcvmore = msg_->flags & ZMQ_MSG_MORE; + rcvmore = msg_->flags () & msg_t::more; if (rcvmore) - msg_->flags &= ~ZMQ_MSG_MORE; + msg_->reset_flags (msg_t::more); } return rc; } @@ -585,9 +584,9 @@ int zmq::socket_base_t::recv (::zmq_msg_t *msg_, int flags_) block = true; } - rcvmore = msg_->flags & ZMQ_MSG_MORE; + rcvmore = msg_->flags () & msg_t::more; if (rcvmore) - msg_->flags &= ~ZMQ_MSG_MORE; + msg_->reset_flags (msg_t::more); return 0; } @@ -757,7 +756,7 @@ bool zmq::socket_base_t::xhas_out () return false; } -int zmq::socket_base_t::xsend (zmq_msg_t *msg_, int options_) +int zmq::socket_base_t::xsend (msg_t *msg_, int options_) { errno = ENOTSUP; return -1; @@ -768,7 +767,7 @@ bool zmq::socket_base_t::xhas_in () return false; } -int zmq::socket_base_t::xrecv (zmq_msg_t *msg_, int options_) +int zmq::socket_base_t::xrecv (msg_t *msg_, int options_) { errno = ENOTSUP; return -1; |