[zeromq-dev] How to use polling in cppzmq (Was: C++ programming help)

Brett Viren bv at bnl.gov
Fri Mar 13 15:37:19 CET 2020

Stepping back, I guess with cppzmq one need not ("should" not) drop down
to libzmq for polling.

Here's an example of using zmq::poller_t with a couple sockets.  It may
not be properly idiomatic (please comment on better form), but maybe it

    zmq::poller_t<> poller;
    poller.add(pipe, zmq::event_flags::pollin);
    poller.add(sock, zmq::event_flags::pollin);

    int nevents = poller.wait_all(events, timeout);
    for (int iev=0; iev < nevents; ++iev) {

        if (events[iev].socket == sock) {
            // service sock

        if (events[iev].socket == pipe) {
            // service pipe

        if (!nevents) {
            // handle timeout

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20200313/92166499/attachment.sig>

More information about the zeromq-dev mailing list