Is there a way to query the size of the received message, when using zero-copy for receiving?
With this I (try to) achieve zero-copy:
zmq_recv(sock, buf, sizeof(buf), 0);
I also tried:
zmq_msg_t msg;
zmq_msg_init_data (&msg, buf, sizeof(buf), nullptr, NULL);
zmq_msg_recv(&msg, sock, 0);
size_t len = zmq_msg_size(&msg);
This returns correct size, but does not fill buf. I think zmq_msg_init_data is not intended for use with zmq_msg_recv and the message rebuilds on receive.
Quoting the guide on zero-copy:
There is no way to do zero-copy on receive: ZeroMQ delivers you a buffer that you can store as long as you wish, but it will not write data directly into application buffers.
Zero-copy is for sending only, not for receiving.
Oh and zmq_recv returns the number of bytes received.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With