Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sockopt::rcvtimeo argument too small #642

Open
jwmelto opened this issue Oct 22, 2024 · 1 comment
Open

sockopt::rcvtimeo argument too small #642

jwmelto opened this issue Oct 22, 2024 · 1 comment

Comments

@jwmelto
Copy link

jwmelto commented Oct 22, 2024

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

@gummif
Copy link
Member

gummif commented Nov 19, 2024

Thanks for that. It would be possible to add an overload for durations, something like

    template<class T>
    void set(sockopt::integral_option<ZMQ_RCVTIMEO, int, false>, duration<T> val)
    {
        // ...
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants