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

Reply via email to