Skip to content

Commit

Permalink
Enable shared-memory in shared-memory examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Mallets committed Nov 20, 2023
1 parent 72f8a1c commit 9cde95c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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

0 comments on commit 9cde95c

Please sign in to comment.