Skip to content
Open
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
16 changes: 11 additions & 5 deletions examples/examples/z_pub_shm_thr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
// ZettaScale Zenoh Team, <zenoh@zettascale.tech>
//
use clap::Parser;
use zenoh::{bytes::ZBytes, qos::CongestionControl, shm::ShmProviderBuilder, Config, Wait};
use zenoh::{
bytes::ZBytes, key_expr::KeyExpr, qos::CongestionControl, shm::ShmProviderBuilder, Config, Wait,
};
use zenoh_examples::CommonArgs;

#[tokio::main]
async fn main() {
// initiate logging
zenoh::init_log_from_env_or("error");
let (config, sm_size, size) = parse_args();
let (config, sm_size, size, key_expr) = parse_args();

let z = zenoh::open(config).await.unwrap();

Expand All @@ -37,7 +39,7 @@ async fn main() {
}

let publisher = z
.declare_publisher("test/thr")
.declare_publisher(key_expr)
// Make sure to not drop messages because of congestion control
.congestion_control(CongestionControl::Block)
.await
Expand All @@ -59,13 +61,17 @@ struct Args {
shared_memory: usize,
/// Sets the size of the payload to publish.
payload_size: usize,
/// The key expression to be used for the throughput test
#[arg(short, long, default_value = "test/thr")]
key_expr: KeyExpr<'static>,
///Common args for all examples
#[command(flatten)]
common: CommonArgs,
}

fn parse_args() -> (Config, usize, usize) {
fn parse_args() -> (Config, usize, usize, KeyExpr<'static>) {
let args = Args::parse();
let sm_size = args.shared_memory * 1024 * 1024;
let size = args.payload_size;
(args.common.into(), sm_size, size)
(args.common.into(), sm_size, size, args.key_expr)
}
7 changes: 6 additions & 1 deletion examples/examples/z_pub_thr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::convert::TryInto;
use clap::Parser;
use zenoh::{
bytes::ZBytes,
key_expr::KeyExpr,
qos::{CongestionControl, Priority},
Wait,
};
Expand All @@ -42,7 +43,7 @@ fn main() {
let session = zenoh::open(args.common).wait().unwrap();

let publisher = session
.declare_publisher("test/thr")
.declare_publisher(args.key_expr)
.congestion_control(CongestionControl::Block)
.priority(prio)
.express(args.express)
Expand Down Expand Up @@ -84,6 +85,10 @@ struct Args {
number: usize,
/// Sets the size of the payload to publish
payload_size: usize,
/// The key expression to be used for the throughput test
#[arg(short, long, default_value = "test/thr")]
key_expr: KeyExpr<'static>,
///Common args for all examples
#[command(flatten)]
common: CommonArgs,
}
25 changes: 11 additions & 14 deletions examples/examples/z_sub_thr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use std::time::Instant;

use clap::Parser;
use zenoh::{Config, Wait};
use zenoh::{key_expr::KeyExpr, Wait};
use zenoh_examples::CommonArgs;

struct Stats {
Expand Down Expand Up @@ -71,24 +71,22 @@ fn main() {
// initiate logging
zenoh::init_log_from_env_or("error");

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

let session = zenoh::open(config).wait().unwrap();
let args = Args::parse();

let key_expr = "test/thr";
let session = zenoh::open(args.common).wait().unwrap();

let mut stats = Stats::new(n);
let mut stats = Stats::new(args.number);
session
.declare_subscriber(key_expr)
.declare_subscriber(args.key_expr)
.callback_mut(move |_sample| {
stats.increment();
if stats.finished_rounds >= m {
if stats.finished_rounds >= args.samples {
std::process::exit(0)
}
})
.background()
.wait()
.unwrap();
.expect("Failed to open Zenoh session");

Copilot AI Apr 6, 2026

Copy link

Choose a reason for hiding this comment

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

The error message passed to expect() is misleading here: the failing operation is the subscriber declaration/background start, not opening the Zenoh session (which already happened above). Use an error message that reflects the actual failing call (e.g., declaring/starting the subscriber), or move the expect() to the zenoh::open(...) call.

Suggested change
.expect("Failed to open Zenoh session");
.expect("Failed to declare/start Zenoh subscriber");

Copilot uses AI. Check for mistakes.

@fuzzypixelz fuzzypixelz Apr 17, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@kydos Copilot is right here, but I would rather write "Failed to declare subscriber".


println!("Press CTRL-C to quit...");
std::thread::park();
Expand All @@ -102,11 +100,10 @@ struct Args {
#[arg(short, long, default_value = "100000")]
/// Number of messages in each throughput measurements.
number: usize,
/// The key expression to be used for the throughput test
#[arg(short, long, default_value = "test/thr")]
key_expr: KeyExpr<'static>,
///Common args for all examples
#[command(flatten)]
common: CommonArgs,
}

fn parse_args() -> (Config, usize, usize) {
let args = Args::parse();
(args.common.into(), args.samples, args.number)
}
Loading