summaryrefslogtreecommitdiff
path: root/gr-zeromq/lib/base_impl.cc
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2021-02-12 15:55:43 +0100
committerMartin Braun <martin@gnuradio.org>2021-02-15 01:11:10 -0800
commitec3d116546aa9710b324b1713cea058d80c906a8 (patch)
treee5f17655468142d8dbed1becab68a4076f017cca /gr-zeromq/lib/base_impl.cc
parent0351066c8b2398eb5894d89fd8ed37cdab43368d (diff)
zeromq: Fix warnings with recv()
The recv() call on a ZMQ socket produces a warning if the return value is not stored. We follow the advice and check the return value, just in case. Signed-off-by: Martin Braun <martin.braun@ettus.com>
Diffstat (limited to 'gr-zeromq/lib/base_impl.cc')
-rw-r--r--gr-zeromq/lib/base_impl.cc30
1 files changed, 18 insertions, 12 deletions
diff --git a/gr-zeromq/lib/base_impl.cc b/gr-zeromq/lib/base_impl.cc
index e6bddc603d..3a8cfcfb82 100644
--- a/gr-zeromq/lib/base_impl.cc
+++ b/gr-zeromq/lib/base_impl.cc
@@ -210,10 +210,16 @@ bool base_source_impl::load_message(bool wait)
/* Get the message */
#if USE_NEW_CPPZMQ_SEND_RECV
- d_socket.recv(d_msg);
+ const bool ok = bool(d_socket.recv(d_msg));
#else
- d_socket.recv(&d_msg);
+ const bool ok = d_socket.recv(&d_msg);
#endif
+ if (!ok) {
+ // This shouldn't happen since we polled POLLIN, but ZMQ wants us to check
+ // the return value.
+ GR_LOG_WARN(d_logger, "Failed to recv() message.");
+ return false;
+ }
/* Throw away key and get the first message. Avoid blocking if a multi-part
* message is not sent */
@@ -222,14 +228,18 @@ bool base_source_impl::load_message(bool wait)
d_socket.getsockopt(ZMQ_RCVMORE, &is_multipart, &more_len);
d_msg.rebuild();
- if (is_multipart)
+ if (is_multipart) {
#if USE_NEW_CPPZMQ_SEND_RECV
- d_socket.recv(d_msg);
+ const bool multi_ok = bool(d_socket.recv(d_msg));
#else
- d_socket.recv(&d_msg);
+ const bool multi_ok = d_socket.recv(&d_msg);
#endif
- else
+ if (!multi_ok) {
+ GR_LOG_ERROR(d_logger, "Failure to receive multi-part message.");
+ }
+ } else {
return false;
+ }
}
/* Parse header from the first (or only) message of a multi-part message */
if (d_pass_tags && !more) {
@@ -246,10 +256,8 @@ bool base_source_impl::load_message(bool wait)
/* Each message must contain an integer multiple of data vectors */
if ((d_msg.size() - d_consumed_bytes) % d_vsize != 0) {
- throw std::runtime_error(
- boost::str(boost::format("Incompatible vector sizes: "
- "need a multiple of %1% bytes per message") %
- d_vsize));
+ throw std::runtime_error("Incompatible vector sizes: need a multiple of " +
+ std::to_string(d_vsize) + " bytes per message");
}
/* We got one ! */
@@ -258,5 +266,3 @@ bool base_source_impl::load_message(bool wait)
} /* namespace zeromq */
} /* namespace gr */
-
-// vim: ts=2 sw=2 expandtab