Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CharlesB2 opened this issue Feb 8, 2018 · 1 comment
Open

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

CharlesB2 opened this issue Feb 8, 2018 · 1 comment

Comments

@CharlesB2
Copy link

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& )?

@benjamg
Copy link
Member

benjamg commented Apr 10, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants