Skip to content

Implement move semantics for context_t and socket_t classes#14

Closed
jp-pino wants to merge 3 commits into
mainfrom
jp-pino/fiz-zmq-move
Closed

Implement move semantics for context_t and socket_t classes#14
jp-pino wants to merge 3 commits into
mainfrom
jp-pino/fiz-zmq-move

Conversation

@jp-pino

@jp-pino jp-pino commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

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:

  • Move semantics for context_t: Added move constructor and assignment operator to efficiently transfer ownership of the ZeroMQ context, ensuring the moved-from object avoids double closures.
  • Move semantics for socket_t: Implemented move constructor and assignment operator for the socket_t class, ensuring the moved-from object avoids double closures.

Robustness improvements:

  • Disallow copy and move operations for msg_t: Explicitly deleted copy constructor, copy assignment operator, move constructor, and move assignment operator for msg_t to ensure proper handling of message resources.

Minor updates:

  • Expanded test coverage: Modified tests/proto/zmq_proto.cpp to include tests for move semantics and resource management, verifying that handles are correctly transferred and invalidated.
  • Documentation improvements: Updated comments in tyndall/proto/zmq_proto.h to clarify error codes and behavior in the recv_more function.

- Also disables copy in msg_t to avoid double free situations
@jp-pino jp-pino added this to the Blunux v4.5 milestone Jul 9, 2025
@jp-pino jp-pino self-assigned this Jul 9, 2025
@jp-pino jp-pino added the enhancement New feature or request label Jul 9, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_t and socket_t
  • Deleted copy/move operations for msg_t to prevent double deallocations
  • Expanded tests for socket moves and clarified recv_more documentation in zmq_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_more comment 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_t move semantics are not tested. Add a test that moves the context (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_t is 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);

Comment thread tyndall/proto/zmq_proto.h
Comment thread tyndall/proto/zmq_proto.h
Comment thread tests/proto/zmq_proto.cpp Outdated
@jp-pino

jp-pino commented Aug 13, 2025

Copy link
Copy Markdown
Contributor Author

These files have been completely removed from Tyndall now as we've opted for the nicer azmq. Closing this PR as it's not relevant now.

@jp-pino jp-pino closed this Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants