[zeromq-dev] Message initialisation

Jonas Thiem jonasthiem at googlemail.com
Fri May 2 13:17:29 CEST 2014


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I think double close similar to a double free is usually considered a
notable programming error and it could hint at a larger problem in the
calling application.

I would suggest keeping an error on second close, similar to e.g.
glibc catching a double free quite safely with a loud and noisy
verbose error. That encourages people to write clean code and keep
track of their open stuff properly. (This is just my opinion though)

Regards,
Jonas Thiem

On 05/02/2014 10:53 AM, Pieter Hintjens wrote:
> The API is persistently confusing... I wonder if there's a way to
> improve it.
> 
> Certainly close should be safe to call in all cases without
> worrying about the previous state.
> 
> On Fri, May 2, 2014 at 12:50 AM, KIU Shueng Chuan
> <nixchuan at gmail.com> wrote:
>>> 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; zmq_msg_init(&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?
>> 
>> A closed message is the same as an uninitialized zmq_msg_t. It
>> becomes just a blob of memory.
>> 
>> Implementation-wise, close scrubs away some magic id that
>> identifies it as being initialized or not. That's why the second
>> close fails.
>> 
>> It would be simpler just to ignore the part about send nullifying
>> the message on success. Just pair every init with a close.
>> 
>> 
>> _______________________________________________ zeromq-dev
>> mailing list zeromq-dev at lists.zeromq.org 
>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>> 
> _______________________________________________ zeromq-dev mailing
> list zeromq-dev at lists.zeromq.org 
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBAgAGBQJTY37DAAoJEBIDTbbx8YkejWkP/2u8Gi9NBSSiRF2XJe1iC5zC
IH48yhOS1pN9E7Htv2OdyGtXXz4GxDMKspjWeiDqTClhlT9VoaHAQzZj6zCJsMKK
W/MsCkP3V5uwIBfAqLgwAAxXj6cMvaVaXfA9OuOj4l5p9D5zN4Iafki4PRBn6Txg
NT6tmL4kvPBkuLLJ79WjZaHNdaLLVX0I0nxUJmAbLHKjUVYh5+9vkOLD7PL8GjeD
1eJ2kuzwfdtcda69h1FqRkGh/vJCjmiAdDwlU5mfIq6is0cmjLmvyLtDcy/SEqKF
0fVwtb7MFqoi0A0N4V0I3vJCk+sGcyDEv5SXecuA1+H0IZokeooWxQFa0vDtPjGV
EAOdEEvgqJlGULu+xob1z3LUR/n+Uyxe+XCMsMWlM3EbMAe8VPRuTPzibKHbtrHu
/IxRF8q4XBuOXGcoSe9Ywp4GXR5XyuUjlBfOP9Wx/gp97HoUUxPkAjj/UfZbZNqq
9DoYl/hTaLr5W4pr4PzsABPBAzfM6rJxdngoN2S3k0wng5rCtB1tIO8P56x1+gi0
7JMw6aRqtpgV+yrTTb/mpRB3pVvXmcMUfOxb9BsrjeIswP3x4ZL0ATDQc4BpYWsk
GQEHMdVy4mSR2di6NYofhUZaLqTnT7RT0EiB9BrM4r7nmnWUPHU6cgX9JOkmnpdS
so7bWPRxkGT5ESfLaqgr
=F7NP
-----END PGP SIGNATURE-----



More information about the zeromq-dev mailing list