Skip to content

Commit

Permalink
Add an --no-stdin option to prevent z_sub_thr from reading early EOF
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry73204 committed Jan 12, 2024
1 parent 6ebe530 commit 10b3b5a
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions examples/examples/z_sub_thr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//
use clap::Parser;
use std::io::{stdin, Read};
use std::time::Instant;
use std::time::{Duration, Instant};
use zenoh::config::Config;
use zenoh::prelude::sync::*;
use zenoh_examples::CommonArgs;
Expand Down Expand Up @@ -72,7 +72,7 @@ fn main() {
// initiate logging
env_logger::init();

let (mut config, m, n) = parse_args();
let (mut config, m, n, no_stdin) = 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
Expand All @@ -95,10 +95,16 @@ fn main() {
.res()
.unwrap();

for byte in stdin().bytes() {
match byte {
Ok(b'q') => break,
_ => std::thread::yield_now(),
if no_stdin {
loop {
std::thread::park();
}
} else {
for byte in stdin().bytes() {
match byte {
Ok(b'q') => break,
_ => std::thread::yield_now(),
}
}
}
}
Expand All @@ -111,11 +117,14 @@ struct Args {
#[arg(short, long, default_value = "100000")]
/// Number of messages in each throughput measurements.
number: usize,
/// Do not read standard input.
#[arg(long)]
no_stdin: bool,
#[command(flatten)]
common: CommonArgs,
}

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

0 comments on commit 10b3b5a

Please sign in to comment.