[zeromq-dev] Feature request: "transmit size" on zmq_msg_t packets

Matt Weinstein matt_weinstein at yahoo.com
Thu Jun 24 16:30:39 CEST 2010


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,



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
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev

More information about the zeromq-dev mailing list