summaryrefslogtreecommitdiff
path: root/src/fq.cpp
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2011-04-21 22:27:48 +0200
committerMartin Sustrik <sustrik@250bpm.com>2011-04-21 22:27:48 +0200
commite0246e32d79d71f8e73207b43aed8b23648e4fc7 (patch)
tree9952ee6fd39f4e27bbe932f6b6f30f0073009369 /src/fq.cpp
parent581697695aac72894f2d3fefac904b9d50b3ba67 (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/fq.cpp')
-rw-r--r--src/fq.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/fq.cpp b/src/fq.cpp
index 36fd435..20dc769 100644
--- a/src/fq.cpp
+++ b/src/fq.cpp
@@ -18,12 +18,11 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "../include/zmq.h"
-
#include "fq.hpp"
#include "pipe.hpp"
#include "err.hpp"
#include "own.hpp"
+#include "msg.hpp"
zmq::fq_t::fq_t (own_t *sink_) :
active (0),
@@ -95,10 +94,11 @@ void zmq::fq_t::activated (reader_t *pipe_)
active++;
}
-int zmq::fq_t::recv (zmq_msg_t *msg_, int flags_)
+int zmq::fq_t::recv (msg_t *msg_, int flags_)
{
// Deallocate old content of the message.
- zmq_msg_close (msg_);
+ int rc = msg_->close ();
+ errno_assert (rc == 0);
// Round-robin over the pipes to get the next message.
for (int count = active; count != 0; count--) {
@@ -116,7 +116,7 @@ int zmq::fq_t::recv (zmq_msg_t *msg_, int flags_)
// and replaced by another active pipe. Thus we don't have to increase
// the 'current' pointer.
if (fetched) {
- more = msg_->flags & ZMQ_MSG_MORE;
+ more = msg_->flags () & msg_t::more;
if (!more) {
current++;
if (current >= active)
@@ -134,7 +134,8 @@ int zmq::fq_t::recv (zmq_msg_t *msg_, int flags_)
// No message is available. Initialise the output parameter
// to be a 0-byte message.
- zmq_msg_init (msg_);
+ rc = msg_->init ();
+ errno_assert (rc == 0);
errno = EAGAIN;
return -1;
}