diff options
author | Matt Mills <mmills@2bn.net> | 2020-10-27 16:11:06 -0600 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2020-10-28 14:12:32 -0400 |
commit | 15efb1ed8d089b3e5ef2aac7f55f483e36d4866d (patch) | |
tree | 91bfab0697d54de3ca9dbd4cc90d1ae43e76b42f | |
parent | f1c27cc85678367924b90eadf80fc0ae0fbb0c09 (diff) |
zeromq: Add ZMQ_LINGER value to prevent infinite block
Closes: #1132
Per the ZMQ documentation update, the docs originally listed the default
of ZMQ_LINGER as 30 seconds, however the real default was -1.
This caused the behavior of blocking indefinitely on top_block.stop()
while the socket waited for abandoned messages to be read by a client.
Ideally this value should be configurable, I've opened #3872 as follow up.
-rw-r--r-- | gr-zeromq/lib/base_impl.cc | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/gr-zeromq/lib/base_impl.cc b/gr-zeromq/lib/base_impl.cc index 5889490898..6b573211dd 100644 --- a/gr-zeromq/lib/base_impl.cc +++ b/gr-zeromq/lib/base_impl.cc @@ -16,6 +16,10 @@ #include "tag_headers.h" #include <gnuradio/io_signature.h> +namespace { +constexpr int LINGER_DEFAULT = 1000; // 1 second. +} + namespace gr { namespace zeromq { @@ -72,6 +76,9 @@ base_sink_impl::base_sink_impl(int type, #endif } + /* Set ZMQ_LINGER so socket won't infinitely block during teardown */ + d_socket.setsockopt(ZMQ_LINGER, &LINGER_DEFAULT, sizeof(LINGER_DEFAULT)); + /* Bind */ d_socket.bind(address); } @@ -143,6 +150,9 @@ base_source_impl::base_source_impl(int type, #endif } + /* Set ZMQ_LINGER so socket won't infinitely block during teardown */ + d_socket.setsockopt(ZMQ_LINGER, &LINGER_DEFAULT, sizeof(LINGER_DEFAULT)); + /* Connect */ d_socket.connect(address); } |