Skip to content

C/C++: add server callbacks for on_un/subscribe #274

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

Merged
merged 6 commits into from
Mar 10, 2025

Conversation

jtbandes
Copy link
Member

@jtbandes jtbandes commented Mar 7, 2025

Changelog

  • C/C++: added server options with callback functions for subscribe and unsubscribe
  • C/C++: added getter for channel id

Docs

N/A

Description

In addition to the features mentioned above:

  • Updated C++ example server to log subscribe/unsubscribe events
  • Added end-to-end C++ test using websocketpp asio client
  • Changed some string_view to string because I learned that string_view is not necessarily null-terminated, but on the Rust side we assume it is

Copy link

linear bot commented Mar 7, 2025

Copy link
Contributor

@eloff eloff left a comment

Choose a reason for hiding this comment

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

Some minor comments, otherwise looking great

};

class Channel final {
public:
Channel(std::string_view topic, std::string_view messageEncoding, std::optional<Schema> schema);
Channel(
const std::string& topic, const std::string& messageEncoding, std::optional<Schema> schema
Copy link
Contributor

Choose a reason for hiding this comment

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

The other option is change the C api to take string pointer and length for each argument, but all our strings are pretty short here, null-terminated strings are fine.

Copy link
Member Author

@jtbandes jtbandes Mar 10, 2025

Choose a reason for hiding this comment

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

yeah - I guess I had two thoughts on that:

  1. const char* (null terminated) seems pretty normal/expected for a C API
  2. if we passed pointer+length, on the Rust side then we wouldn't be able to use CStr::from_ptr, which is not the end of the world, but on the other hand this is exactly what it's designed for.

And another one: because C++ is stupid, technically you can also have a std::string that contains null bytes, so I think I'm viewing this API more as "advice" that the strings you pass in should be null-terminated.

@jtbandes jtbandes merged commit 672e54f into main Mar 10, 2025
36 checks passed
@jtbandes jtbandes deleted the jacob/fg-10676-cc-add-ws-server-listener branch March 10, 2025 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants