Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zero-copy receive and message size

Tags:

zeromq

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.

like image 241
Daniel Bulla Avatar asked Nov 01 '25 23:11

Daniel Bulla


1 Answers

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.

like image 55
rveerd Avatar answered Nov 04 '25 11:11

rveerd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!