Skip to content

Commit

Permalink
Add 'shared_memory' config in shm examples
Browse files Browse the repository at this point in the history
  • Loading branch information
JEnoch committed Nov 23, 2023
1 parent 8954a81 commit 808c9df
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
9 changes: 7 additions & 2 deletions examples/examples/z_pub_shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ async fn main() -> Result<(), zenoh::Error> {
// Initiate logging
env_logger::init();

let (config, path, value) = parse_args();
let (mut config, path, value) = parse_args();

// 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.
config.transport.shared_memory.set_enabled(true).unwrap();

println!("Opening session...");
let session = zenoh::open(config).res().await.unwrap();
Expand All @@ -39,6 +44,7 @@ async fn main() -> Result<(), zenoh::Error> {
let publisher = session.declare_publisher(&path).res().await.unwrap();

for idx in 0..(K * N as u32) {
sleep(Duration::from_secs(1)).await;
let mut sbuf = match shm.alloc(1024) {
Ok(buf) => buf,
Err(_) => {
Expand Down Expand Up @@ -88,7 +94,6 @@ async fn main() -> Result<(), zenoh::Error> {
let defrag = shm.defragment();
println!("De-framented {defrag} bytes");
}
// sleep(Duration::from_millis(100)).await;
// Dropping the SharedMemoryBuf means to free it.
drop(sbuf);
}
Expand Down
7 changes: 6 additions & 1 deletion examples/examples/z_pub_shm_thr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ use zenoh::shm::SharedMemoryManager;
async fn main() {
// initiate logging
env_logger::init();
let (config, sm_size, size) = parse_args();
let (mut config, sm_size, size) = parse_args();

// A probing procedure for shared memory is performed upon session opening. To enable `z_pub_shm_thr` 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.
config.transport.shared_memory.set_enabled(true).unwrap();

let z = zenoh::open(config).res().await.unwrap();
let id = z.zid();
Expand Down
7 changes: 6 additions & 1 deletion examples/examples/z_sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ async fn main() {
// Initiate logging
env_logger::init();

let (config, key_expr) = parse_args();
let (mut config, key_expr) = parse_args();

// 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.
config.transport.shared_memory.set_enabled(true).unwrap();

println!("Opening session...");
let session = zenoh::open(config).res().await.unwrap();
Expand Down
7 changes: 6 additions & 1 deletion examples/examples/z_sub_thr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ fn main() {
// initiate logging
env_logger::init();

let (config, m, n) = parse_args();
let (mut config, m, n) = parse_args();

// A probing procedure for shared memory is performed upon session opening. To enable `z_pub_shm_thr` 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.
config.transport.shared_memory.set_enabled(true).unwrap();

let session = zenoh::open(config).res().unwrap();

Expand Down

0 comments on commit 808c9df

Please sign in to comment.