[zeromq-dev] Message initialisation

Lars Tandle Kyllingstad lars at kyllingen.net
Thu May 1 18:35:13 CEST 2014


I have a few questions regarding message initialisation and destruction.

According to the zmq_msg_send() reference, a zmq_msg_t is "nullified" 
after it has been sent.  It does not specify exactly what "nullify" 
means, but I seem to remember reading elsewhere that it is set to the 
same state as after a successful zmq_msg_init() call.  Is this correct?

The zmq_msg_close() reference further says that a message does not need 
to be closed after a zmq_msg_send() call.  Presumably, this means that 
it is not necessary to close it after zmq_msg_init() either, provided it 
has not been used to receive a message in the meantime.  Correct?

zmq_msg_close() does not return with an error code when applied to an 
"empty" zmq_msg_t, neither one that has just been sent nor one that has 
been initialised as empty.  However, if I call it *again* on the same 
message, it fails:

     zmq_msg_t m;
     assert(zmq_msg_close(&m) == 0); // Passes
     assert(zmq_msg_close(&m) == 0); // Fails

In other words, closing an empty message is apparently not a no-op.  So, 
what is the difference between an empty message and a closed message?

And my final question:  Is zmq_msg_init_size(&m, 0) by definition 
equivalent to zmq_msg_init(&m)?  I have looked at the source code, and 
it seems the two cases are currently implemented in the same way, but my 
question is whether this is by specification, or whether it is an 
implementation detail that may change in future versions.

The reason I'm asking is that I'm writing a ZMQ wrapper for the D 
programming language, and it is important that I get the message 
constructors and destructor right. :)

If anyone is interested in my work, check out:


It has been pretty well received by the D community, but comments and 
feedback from experts in the ZMQ community is very welcome!

Lars T. Kyllingstad

More information about the zeromq-dev mailing list