From fd87764ebc8733b44bc4a43a180b635ce190a123 Mon Sep 17 00:00:00 2001 From: imarom Date: Mon, 27 Feb 2017 14:46:46 +0200 Subject: ZMQ publisher might hang if it sends a message during ctrl + c the reason is that when calling zmq_close and zmq_term from the same thread, zmq_close will wait for the message to be sent (but will return the control to the calling thread) and then zmq_ctx_destroy will hang forever see: https://lists.zeromq.org/pipermail/zeromq-dev/2013-September/022469.html Signed-off-by: imarom --- src/publisher/trex_publisher.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/publisher') diff --git a/src/publisher/trex_publisher.cpp b/src/publisher/trex_publisher.cpp index dc37d14c..f5437378 100644 --- a/src/publisher/trex_publisher.cpp +++ b/src/publisher/trex_publisher.cpp @@ -73,6 +73,13 @@ TrexPublisher::Create(uint16_t port, bool disable){ void TrexPublisher::Delete(){ if (m_publisher) { + + /* before calling zmq_close set the linger property to zero + (othersie zmq_ctx_destroy might hang forever) + */ + int val = 0; + zmq_setsockopt(m_publisher, ZMQ_LINGER, &val, sizeof(val)); + zmq_close (m_publisher); m_publisher = NULL; } -- cgit 1.2.3-korg