cppzmq icon indicating copy to clipboard operation
cppzmq copied to clipboard

sockopt::rcvtimeo argument too small

Open jwmelto opened this issue 1 year ago • 1 comments

I'm updating legacy code to use the new socket options, and ran into an issue:

error: no matching function for call to 'zmq::socket_t::set(const zmq::sockopt::rcvtimeo_t& std::chrono::duration<long int, std::ratio<1, 1000> >::rep)'

The calling user code is like this:

void Send(zmq::socket_t& sock, std::chrono::milliseconds timeout) {
    sock.set(zmq::sockopt::rcvtimeo, timeout.count());
...
}

A richer interface would accept a (templated?) std::chrono::duration, but the specific issue here is the definition of sockopt::rcvtimeo uses int and template substitution fails when provided a long int (std::chrono::milliseconds::rep).

Simply changing the definition of rcvtimeo to take a long int breaks code like

sock.set(zmq::sockopt::rcvtimeo, 42);

and the enumeration-as-helper-type pattern precludes overloads. I don't see a good solution to this issue

jwmelto avatar Oct 22 '24 15:10 jwmelto