From c2f3b3b4458187085e148850068f9719c2567614 Mon Sep 17 00:00:00 2001 From: Jon Dyte Date: Fri, 27 Aug 2010 06:59:55 +0200 Subject: forwarder and streamer devices handle multi-part messages correctly --- src/streamer.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/streamer.cpp') diff --git a/src/streamer.cpp b/src/streamer.cpp index 9799007..7c03365 100644 --- a/src/streamer.cpp +++ b/src/streamer.cpp @@ -21,6 +21,7 @@ #include "streamer.hpp" #include "socket_base.hpp" +#include "likely.hpp" #include "err.hpp" int zmq::streamer (socket_base_t *insocket_, socket_base_t *outsocket_) @@ -29,16 +30,26 @@ int zmq::streamer (socket_base_t *insocket_, socket_base_t *outsocket_) int rc = zmq_msg_init (&msg); errno_assert (rc == 0); + int64_t more; + size_t more_sz = sizeof (more); + while (true) { rc = insocket_->recv (&msg, 0); - if (rc < 0) { + if (unlikely (rc < 0)) { + if (errno == ETERM) + return -1; + errno_assert (false); + } + + rc = insocket_->getsockopt (ZMQ_RCVMORE, &more, &more_sz); + if (unlikely (rc < 0)) { if (errno == ETERM) return -1; errno_assert (false); } - rc = outsocket_->send (&msg, 0); - if (rc < 0) { + rc = outsocket_->send (&msg, more ? ZMQ_SNDMORE : 0); + if (unlikely (rc < 0)) { if (errno == ETERM) return -1; errno_assert (false); -- cgit v1.2.3