ZMQ publisher might hang if it sends a message during ctrl + c
authorimarom <[email protected]>
Mon, 27 Feb 2017 12:46:46 +0000 (14:46 +0200)
committerimarom <[email protected]>
Mon, 27 Feb 2017 12:49:49 +0000 (14:49 +0200)
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 <[email protected]>
src/publisher/trex_publisher.cpp

index dc37d14..f543737 100644 (file)
@@ -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;
     }