[zeromq-dev] Docs: incorrect semantics

john skaller skaller at users.sourceforge.net
Sun Jan 15 08:12:25 CET 2012


zmq_msg_init_data(3)

"Never initialize the same zmq_msg_t twice."

This is incorrect. The example on page: 
http://api.zeromq.org/3-1:zmq-getmsgopt

does precisely that:

zmq_msg_t part;
int more;
size_t more_size = sizeof (more);
while (true) {
    /* Create an empty ØMQ message to hold the message part */
    int rc = zmq_msg_init (&part);
    assert (rc == 0);
    /* Block until a message is available to be received from socket */
    rc = zmq_recvmsg (socket, &part, 0);
    assert (rc != -1);
    rc = getmsgopt (&part, ZMQ_MORE, &more, &more_size);
    assert (rc == 0);
    if (more) {
      fprintf (stderr, "more\n");
    }
    else {
      fprintf (stderr, "end\n");
      break;
    }
    zmq_msg_close (part); }

"part" is initialised once for every time around the loop.

What should have been said is that close uninitialises a zmq_msg_t,
an uninitialised zmq_msg_t must be initialised before use by any other
function (than one of the 3 initialisers), and, it may not be initialised if
it is already initialised .. (or better words to this effect).

In fact I did misinterpret this. See prior post: I put zmq_msg_close
in the finaliser, which means it would be invoked only once.
As it happens my semantics would work because the only way to make
one would initialise it, but there'd be no way to *reuse* it in the way
the above C program does.

Which leads to the question: what does move do?
Docs say the source becomes an empty message.. which implies it is
still initialised, right?

--
john skaller
skaller at users.sourceforge.net







More information about the zeromq-dev mailing list