[zeromq-dev] ZMQ 4.0.5 -- Error in ZMQ_RECVMORE example ?

Scott alcoholiday at gmail.com
Sun Jan 4 00:57:08 CET 2015

In the following sample code from website, you can get inconsistent
results since 'getsockopt' stores and (int) 0 or 1 in the thing
pointed at with the &more reference, which in this case is an int64 as
opposed int32.

That said, as you can see the function does dutifully set the length
of the value returned in more_size, but this code only works if the
upper part of more is initialized to zero, or if one bothers looking
at the length.

I'm embarrassed to say how long I spent wondering why I was getting
more multi-part messages than I'd expect!

---from getsockopt---

      *((int*) optval_) = rcvmore ? 1 : 0;      *optvallen_ = sizeof (int);

---sample code---

int64_t more;
size_t more_size = sizeof more;
do {
    /* Create an empty ØMQ message to hold the message part */
    zmq_msg_t part;
    int rc = zmq_msg_init (&part);
    assert (rc == 0);
    /* Block until a message is available to be received from socket */
    rc = zmq_recv (socket, &part, 0);
    assert (rc == 0);
    /* Determine if more message parts are to follow */
    rc = zmq_getsockopt (socket, ZMQ_RCVMORE, &more, &more_size);
    assert (rc == 0);
    zmq_msg_close (&part); } while (more);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20150103/60f4bc8f/attachment.htm>

More information about the zeromq-dev mailing list