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

cppzmq docs for poll are wrong #858

Open
TobiSchluter opened this issue Jul 26, 2021 · 3 comments
Open

cppzmq docs for poll are wrong #858

TobiSchluter opened this issue Jul 26, 2021 · 3 comments

Comments

@TobiSchluter
Copy link

TobiSchluter commented Jul 26, 2021

The example does the following to initialize the poller:

    zmq::pollitem_t items [] = {
        { static_cast<void*>(receiver), 0, ZMQ_POLLIN, 0 },
        { static_cast<void*>(subscriber), 0, ZMQ_POLLIN, 0 }
    };

The correct way to do this is to use the implicit conversion of zmq::socket_t to void*, i.e.

    zmq::pollitem_t items [] = {
        { receiver, 0, ZMQ_POLLIN, 0 },
        { subscriber, 0, ZMQ_POLLIN, 0 }
    };

I needed StackOverflow to figure out this issue https://stackoverflow.com/questions/16429907/zmq-poll-not-working

To be frank, I don't really understand the failure mode (I'm using references ìn the place of receiver and subscriber, and I'm getting ERRNOSOCK when calling zmq_poll), but it's clear that the intent of zmq::socket_t is that it be used without the static_cast.

@sappo
Copy link
Member

sappo commented Jul 26, 2021

Hi @TobiSchluter, thanks for reporting the bug. It would be great if you could fix the example and send a PR :)

@TobiSchluter
Copy link
Author

Well, I'm no longer sure what the intended way to do this is given this comment in zmq.hpp:

// note: non-const operator bool can be removed once
// operator void* is removed from socket_t
ZMQ_EXPLICIT operator bool() ZMQ_NOTHROW { return _handle != ZMQ_NULLPTR; }

It certainly seems to suggest that operator void * is not the proper interface to use.

But sure, PR coming. It's always easier for people "in the know" to step up when there's an actual change :)

@aviallon
Copy link

aviallon commented Oct 31, 2021

Shouldn't this be closed?

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

3 participants