I'm trying to implement a non-blocking receive method with ZeroMQ using the ZMQ_DONTWAIT
flag but recv()
behaves like being called without the flag:
auto start = std::chrono::steady_clock::now();
auto have_data = sock_->recv(&reply, ZMQ_DONTWAIT);
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now() - start).count();
std::cout << duration << " " << have_data;
sock_
is a zmq::socket_t
instantiated as REQ
socket.
In this case have_data
is always true and duration
is whatever the REP
server takes to reply (0 to several hundreds milliseconds).
Note that I'm talking about the cpp binding of ZeroMQ defined in zmq.hpp
where recv()
is differently declared than in zmq.h
:
inline bool recv (message_t *msg_, int flags_ = 0);
Here recv()
returns true
if data has been received and false
if errno
is EAGAIN
Are there any preconditions to ZMQ_DONTWAIT
making recv()
return immediately?
(I'm using zmq
version 4.1.2)