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/session.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/session.cpp')
-rw-r--r-- | src/session.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/session.cpp b/src/session.cpp index 5f970cc..499fe40 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -80,7 +80,7 @@ void zmq::session_t::proceed_with_term () own_t::process_term (0); } -bool zmq::session_t::read (::zmq_msg_t *msg_) +bool zmq::session_t::read (msg_t *msg_) { if (!in_pipe) return false; @@ -88,14 +88,15 @@ bool zmq::session_t::read (::zmq_msg_t *msg_) if (!in_pipe->read (msg_)) return false; - incomplete_in = msg_->flags & ZMQ_MSG_MORE; + incomplete_in = msg_->flags () & msg_t::more; return true; } -bool zmq::session_t::write (::zmq_msg_t *msg_) +bool zmq::session_t::write (msg_t *msg_) { if (out_pipe && out_pipe->write (msg_)) { - zmq_msg_init (msg_); + int rc = msg_->init (); + errno_assert (rc == 0); return true; } @@ -120,13 +121,15 @@ void zmq::session_t::clean_pipes () // Remove any half-read message from the in pipe. if (in_pipe) { while (incomplete_in) { - zmq_msg_t msg; - zmq_msg_init (&msg); + msg_t msg; + int rc = msg.init (); + errno_assert (rc == 0); if (!read (&msg)) { zmq_assert (!incomplete_in); break; } - zmq_msg_close (&msg); + rc = msg.close (); + errno_assert (rc == 0); } } } |