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

Offer better Send/Receive API #85

Open
rbx opened this issue Sep 13, 2018 · 3 comments
Open

Offer better Send/Receive API #85

rbx opened this issue Sep 13, 2018 · 3 comments
Assignees
Labels
feature New feature or request
Milestone

Comments

@rbx
Copy link
Member

rbx commented Sep 13, 2018

Is your feature request related to a problem? Please describe.
The current Send API takes message pointers by reference. The users should not touch the messages after calling Send on it, because it can be sent out at any moment and will be deleted automatically. However if a timeout or some error condition happen, Send will return an status value and the user can touch the message, change it, or resend it. This is not clear with the current API.

Describe the solution you'd like
Instead we should take messages as unique_ptr that user has to std::move to us, giving up the ownership to the transport. To further support giving back the ownership in case of error or a timeout to the user, we should introduce a custom return value that contains a status flag and optional unique_ptr that will contain the message in case of timeout/error. This return value can override the comparison operators for checking of the status flag, which will make it more compatible with the old interface and ease the transition.

Same convention can be used for Receive, where the returned type will contain the received message.

@rbx rbx added the feature New feature or request label Sep 13, 2018
@rbx rbx added this to the v1.4 milestone Sep 13, 2018
@rbx rbx self-assigned this Sep 13, 2018
@dennisklein
Copy link
Member

Was discussing this with Matthias a bit more. Actually, I think we should not expose pointer types to the user at all, but just take and give plain move-only FairMQMessages by value. The same we should imho apply to the FairMQTransportFactory member functions.

@rbx What do you think?

@rbx
Copy link
Member Author

rbx commented Sep 21, 2018

What I have in mind now, especially after considering possibility of having our own header and some other discussions we had, is to offer a new fair::mq::Message class. Which will be:

  • move only.
  • contain multiple buffers/parts that user can read/write/add/remove (if i'm not mistaken this is similar/same to what you once proposed with multiple buffers).
  • will have methods to access header values.
  • ... ?

Internally it can be just built out of FairMQParts (which are also move only and non pointer), where one or more parts are reserved for our headers or anything really, since we will not expose internal parts to user.

Regarding what factory returns i am not certain, it indeed can return those move-only types, but then it has to give up ownership.

@dennisklein
Copy link
Member

dennisklein commented Sep 21, 2018

This article has a lot of answers on how to implement our interfaces with value semantics: https://akrzemi1.wordpress.com/2012/02/03/value-semantics/

Regarding what factory returns i am not certain, it indeed can return those move-only types, but then it has to give up ownership.

Indeed, I was not telling all the details. After thinking about it, the sockets should have shared ownership on the transport, device also has shared ownership on transport. When we need to communicate something to the sockets, we also need to track (non-owning) pointers to the sockets in the transport. Once a socket is destructed, it will deregister itself from the transport. I believe this would be the cleanest implementation. But there is no rush, let's take the time and think it through another couple of times.

... is to offer a new fair::mq::Message class ...

This would be a great migration strategy. If I may rephrase Use the overdue namespacing of some of our classes to introduce a new API in parallel and then deprecate the old API at some point.

@rbx rbx modified the milestones: v1.4, v1.5 Apr 17, 2019
@rbx rbx mentioned this issue Nov 20, 2020
@dennisklein dennisklein modified the milestones: v1.5, v1.6 Aug 12, 2022
@dennisklein dennisklein modified the milestones: v1.6, next Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants