Implement move semantics for context_t and socket_t classes#14
Closed
jp-pino wants to merge 3 commits into
Closed
Conversation
- Also disables copy in msg_t to avoid double free situations
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances resource safety for ZeroMQ wrappers by implementing move semantics, disabling unsafe operations, and improving test coverage and documentation.
- Added move constructors and assignment operators for
context_tandsocket_t - Deleted copy/move operations for
msg_tto prevent double deallocations - Expanded tests for socket moves and clarified
recv_moredocumentation inzmq_proto.h
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tyndall/proto/zmq_proto.h | Added move semantics, disabled msg_t moves, updated destructor guards and comments |
| tests/proto/zmq_proto.cpp | Included basic socket move tests and added <iostream> |
Comments suppressed due to low confidence (3)
tyndall/proto/zmq_proto.h:371
- [nitpick] The updated
recv_morecomment merged multiple bullets into one line, reducing readability. Consider restoring each error case as a separate bullet or line with hyphens for clarity.
empty errno: EBADMSG if the type name didn't match errno: EOPNOTSUPP if
tests/proto/zmq_proto.cpp:19
- The new
context_tmove semantics are not tested. Add a test that moves thecontext(e.g.auto moved = std::move(context);) and verifies the handle transfer and that the original is invalidated.
zmq_proto::context_t context{1};
tests/proto/zmq_proto.cpp:29
- Only the move constructor for
socket_tis tested here. Consider adding a test for the move assignment operator (e.g.pub = std::move(pub_1);) to ensure that path is also verified.
zmq_proto::socket_t<zmq_proto::PUB> pub = std::move(pub_1);
Contributor
Author
|
These files have been completely removed from Tyndall now as we've opted for the nicer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, copying or moving context_t, socket_t, and msg_t could result in double deallocations. This PR makes them safer to use.
Enhancements to resource management:
context_t: Added move constructor and assignment operator to efficiently transfer ownership of the ZeroMQ context, ensuring the moved-from object avoids double closures.socket_t: Implemented move constructor and assignment operator for thesocket_tclass, ensuring the moved-from object avoids double closures.Robustness improvements:
msg_t: Explicitly deleted copy constructor, copy assignment operator, move constructor, and move assignment operator formsg_tto ensure proper handling of message resources.Minor updates:
tests/proto/zmq_proto.cppto include tests for move semantics and resource management, verifying that handles are correctly transferred and invalidated.tyndall/proto/zmq_proto.hto clarify error codes and behavior in therecv_morefunction.