[zeromq-dev] Message initialisation
Pieter Hintjens
ph at imatix.com
Fri May 2 10:53:42 CEST 2014
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
>
More information about the zeromq-dev
mailing list