aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2019-04-16 11:43:11 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2019-04-16 11:43:11 +0200
commit5b765b7320c42130c09eab53043da7c0ea9d43ab (patch)
tree1151d4296ad79aaf74f85c5b19b0733cbf788b72
parent643206925cb2bbc4e30c98dc4a0b29326a11846e (diff)
downloaddabmod-5b765b7320c42130c09eab53043da7c0ea9d43ab.tar.gz
dabmod-5b765b7320c42130c09eab53043da7c0ea9d43ab.tar.bz2
dabmod-5b765b7320c42130c09eab53043da7c0ea9d43ab.zip
Avoid ugly 'context terminated' error on zmq restart
-rw-r--r--src/InputZeroMQReader.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/InputZeroMQReader.cpp b/src/InputZeroMQReader.cpp
index 3661748..1ebc1ca 100644
--- a/src/InputZeroMQReader.cpp
+++ b/src/InputZeroMQReader.cpp
@@ -42,6 +42,8 @@
using namespace std;
+constexpr int ZMQ_TIMEOUT_MS = 100;
+
#define NUM_FRAMES_PER_ZMQ_MESSAGE 4
/* A concatenation of four ETI frames,
* whose maximal size is 6144.
@@ -76,6 +78,9 @@ InputZeroMQReader::InputZeroMQReader() :
InputZeroMQReader::~InputZeroMQReader()
{
m_running = false;
+ // This avoids the ugly "context was terminated" error because it lets
+ // poll do its thing first
+ this_thread::sleep_for(chrono::milliseconds(2 * ZMQ_TIMEOUT_MS));
m_zmqcontext.close();
if (m_recv_thread.joinable()) {
m_recv_thread.join();
@@ -190,8 +195,7 @@ void InputZeroMQReader::RecvProcess()
zmq::pollitem_t items[1];
items[0].socket = subscriber;
items[0].events = ZMQ_POLLIN;
- const int zmq_timeout_ms = 100;
- const int num_events = zmq::poll(items, 1, zmq_timeout_ms);
+ const int num_events = zmq::poll(items, 1, ZMQ_TIMEOUT_MS);
if (num_events == 0) {
message_t msg;
msg.timeout = true;