diff options
author | Vasil Velichkov <vvvelichkov@gmail.com> | 2020-02-20 03:10:38 +0200 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2020-03-10 10:54:30 -0400 |
commit | ff9b489dee9293e1837910990bd2f2b60f5e7fde (patch) | |
tree | 994df48b078b5b51aae38c1527dee9046d77d1a5 | |
parent | 3154f78425bb86934c19a99d21ed965ae6d2410d (diff) |
zmq: Handle the PMT exceptions
Handle the PMT exceptions when deserializing the received ZMQ messages,
log an error message and continue the execution.
Previously the unhandled exceptions were aborting the process:
terminate called after throwing an instance of 'pmt::exception'
what(): pmt::deserialize: malformed input stream, tag value = : 50
Aborted (core dumped)
-rw-r--r-- | gr-zeromq/lib/pull_msg_source_impl.cc | 8 | ||||
-rw-r--r-- | gr-zeromq/lib/req_msg_source_impl.cc | 8 | ||||
-rw-r--r-- | gr-zeromq/lib/sub_msg_source_impl.cc | 9 |
3 files changed, 18 insertions, 7 deletions
diff --git a/gr-zeromq/lib/pull_msg_source_impl.cc b/gr-zeromq/lib/pull_msg_source_impl.cc index 404333e891..651bc530fa 100644 --- a/gr-zeromq/lib/pull_msg_source_impl.cc +++ b/gr-zeromq/lib/pull_msg_source_impl.cc @@ -91,8 +91,12 @@ void pull_msg_source_impl::readloop() std::string buf(static_cast<char*>(msg.data()), msg.size()); std::stringbuf sb(buf); - pmt::pmt_t m = pmt::deserialize(sb); - message_port_pub(d_port, m); + try { + pmt::pmt_t m = pmt::deserialize(sb); + message_port_pub(d_port, m); + } catch (pmt::exception& e) { + GR_LOG_ERROR(d_logger, std::string("Invalid PMT message: ") + e.what()); + } } else { boost::this_thread::sleep(boost::posix_time::microseconds(100)); diff --git a/gr-zeromq/lib/req_msg_source_impl.cc b/gr-zeromq/lib/req_msg_source_impl.cc index c246e3a57c..0118b4d084 100644 --- a/gr-zeromq/lib/req_msg_source_impl.cc +++ b/gr-zeromq/lib/req_msg_source_impl.cc @@ -109,8 +109,12 @@ void req_msg_source_impl::readloop() std::string buf(static_cast<char*>(msg.data()), msg.size()); std::stringbuf sb(buf); - pmt::pmt_t m = pmt::deserialize(sb); - message_port_pub(d_port, m); + try { + pmt::pmt_t m = pmt::deserialize(sb); + message_port_pub(d_port, m); + } catch (pmt::exception& e) { + GR_LOG_ERROR(d_logger, std::string("Invalid PMT message: ") + e.what()); + } } else { boost::this_thread::sleep(boost::posix_time::microseconds(100)); diff --git a/gr-zeromq/lib/sub_msg_source_impl.cc b/gr-zeromq/lib/sub_msg_source_impl.cc index a8fd0a9117..3ead4025f1 100644 --- a/gr-zeromq/lib/sub_msg_source_impl.cc +++ b/gr-zeromq/lib/sub_msg_source_impl.cc @@ -89,9 +89,12 @@ void sub_msg_source_impl::readloop() #endif std::string buf(static_cast<char*>(msg.data()), msg.size()); std::stringbuf sb(buf); - pmt::pmt_t m = pmt::deserialize(sb); - - message_port_pub(d_port, m); + try { + pmt::pmt_t m = pmt::deserialize(sb); + message_port_pub(d_port, m); + } catch (pmt::exception& e) { + GR_LOG_ERROR(d_logger, std::string("Invalid PMT message: ") + e.what()); + } } else { boost::this_thread::sleep(boost::posix_time::microseconds(100)); } |