Quantcast
Channel: Active questions tagged zeromq - Stack Overflow
Viewing all articles
Browse latest Browse all 193

Why does ZMQ context close blocks forever?

$
0
0

I have the following code snippet. There the context.close() blocks forever. Does anyone have a hint on how to fix this? I suspect this is happening because I send a message but never receive an answer, as the close() doesn’t block if I do get a response. The question is, what if I don’t get a response? How can I close the context in this case without causing a deadlock? I use libzmq 4.3.4 and cppzmq 4.7.1.

#include <zmq.h>int main(){ zmq::context_t context(1); zmq::socket_t socket1(context, zmq::socket_type::req); const std::string foo("foo_"); socket1.connect("tcp://127.0.0.1:8889"); zmq::message_t msg(foo.size()); std::memcpy(msg.data(), foo.c_str(), foo.size()); socket1.send(std::move(msg), zmq::send_flags::none); socket1.set(zmq::sockopt::rcvtimeo, 500); //block for 50mms as expected socket1.recv(msg); socket1.disconnect("tcp://127.0.0.1:8889"); socket1.set(zmq::sockopt::linger, 0); socket1.close(); context.close(); //code blocks here, everything else works fine}

Viewing all articles
Browse latest Browse all 193

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>