zeromq/zmqpp

Have a const ref to the message in socket::send?

CharlesB2 opened this issue · 1 comments

I'm not very experienced with 0mq, so correct me if I'm wrong, but it seems like socket::send(message&) doesn't modify the message at all? If no, shouldn't the signature be socket::send(const message& )?

For a successful send we actually swap out the message object so that code, the reasoning behind this, assuming my memory serves, is twofold;

First off, and most importantly the underlying libzmq can modify the sent frame, mostly due to the way it allows zero copy processing. This leaves us with a potentially invalid message structure.

Secondly a lot of code does a loop around the a poller and receives then sends using the same object, by returning a 'new' empty message we allow an easier time for users. Obviously we wouldn't do this if we didn't have an invalid message in the first place, but as we do we take advantage of it.

Sorry its taken me so long to reply, I really need to allocate more time to maintaining this project.

See: https://github.com/zeromq/zmqpp/blob/develop/src/zmqpp/socket.cpp#L205 for the swap code