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

Enable shared-memory in shared-memory examples #194

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/z_pub_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ int main(int argc, char **argv) {
if (argc > 2) value = argv[2];

z_owned_config_t config = z_config_default();
// Enable shared memory
if (zc_config_insert_json(z_loan(config), "transport/shared_memory/enabled", "true") < 0) {
printf("Error enabling Shared Memory");
exit(-1);
}
if (argc > 3) {
if (zc_config_insert_json(z_loan(config), Z_CONFIG_CONNECT_KEY, argv[3]) < 0) {
printf(
Expand Down
7 changes: 7 additions & 0 deletions examples/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ int main(int argc, char **argv) {
exit(-1);
}
}
// A probing procedure for shared memory is performed upon session opening. To enable `z_pub_shm` to operate
// over shared memory (and to not fallback on network mode), shared memory needs to be enabled also on the
// subscriber side. By doing so, the probing procedure will succeed and shared memory will operate as expected.
if (zc_config_insert_json(z_loan(config), "transport/shared_memory/enabled", "true") < 0) {
printf("Error enabling Shared Memory");
exit(-1);
}

printf("Opening session...\n");
z_owned_session_t s = z_open(z_move(config));
Expand Down
Loading