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/session.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/session.cpp') 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); } } } -- cgit v1.2.3