Martin,

This certainly demonstrates that there should be an "idioms" section  
in the cookbook which includes these types of patterns.

Perhaps a pattern wiki (ØMQIKI ?) would be useful for community  
contributions, if you get some spare time :-)

Thank you again,

Best,

Matt

On Jun 24, 2010, at 3:19 AM, Martin Sustrik wrote:

> Matt,
>
>> I'm reading variable length records directly from a MYSQL database,
>> with a defined "max field length" into a dynamically allocated
>> zmq_msg_t buffer, whose size must be the max field length.
>>
>> However, I need to send just the characters I retrieved from the
>> database, not the full buffer, otherwise I must figure out how to  
>> send
>> the data field size to the distant end, or at least I must:
>>
>> 1) null the unused portion of the buffer; or
>> 2) copy to a smaller zmq_msg_t.
>>
>> Both of these require fill or copy operations :-(
>
> You can do it in a following way:
>
> void my_free (void *data, void *hint) {free (data);}
> ...
> char *buf = malloc (MAX_BUFFER_SIZE);
> size_t bytes_used = fill_in_the_buffer (buf);
> zmq_msg_t msg;
> zmq_msg_init_data (msg, buf, bytes_used, my_free, NULL);
> zmq_msg_send (s, msg);
>
> Martin
> _______________________________________________
> zeromq-dev mailing list
> [email protected]
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev

_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to