Skip to content
Open
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
17 changes: 13 additions & 4 deletions gping/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ build_env: {},{}"#,
build::RUST_CHANNEL
);

#[cfg(target_os = "openbsd")]
const DEFAULT_PING_INTERVAL_SECONDS: f32 = 1.0;
#[cfg(not(target_os = "openbsd"))]
const DEFAULT_PING_INTERVAL_SECONDS: f32 = 0.2;
const DEFAULT_CMD_INTERVAL_SECONDS: f32 = 0.5;

#[derive(Parser, Debug)]
#[command(author, version=build::PKG_VERSION, name = "gping", about = "Ping, but with a graph.", long_version = VERSION_INFO, styles = clap_cargo::style::CLAP_STYLING
)]
Expand All @@ -61,7 +67,7 @@ struct Args {
#[arg(long)]
cmd: bool,

/// Watch interval seconds (provide partial seconds like '0.5'). Default for ping is 0.2, default for cmd is 0.5.
/// Watch interval seconds (provide partial seconds like '0.5'). Default for ping is 0.2 (1.0 on OpenBSD), default for cmd is 0.5.
#[arg(short = 'n', long)]
watch_interval: Option<f32>,

Expand Down Expand Up @@ -270,7 +276,9 @@ fn start_cmd_thread(
.to_string();
let cmd_args = words.map(|w| w.to_string()).collect::<Vec<String>>();

let interval = Duration::from_millis((watch_interval.unwrap_or(0.5) * 1000.0) as u64);
let interval = Duration::from_millis(
(watch_interval.unwrap_or(DEFAULT_CMD_INTERVAL_SECONDS) * 1000.0) as u64,
);

// Pump cmd watches into the queue
thread::spawn(move || -> Result<()> {
Expand Down Expand Up @@ -430,8 +438,9 @@ fn main() -> Result<()> {
);
threads.push(cmd_thread);
} else {
let interval =
Duration::from_millis((args.watch_interval.unwrap_or(0.2) * 1000.0) as u64);
let interval = Duration::from_millis(
(args.watch_interval.unwrap_or(DEFAULT_PING_INTERVAL_SECONDS) * 1000.0) as u64,
);

let mut ping_opts = if args.ipv4 {
PingOptions::new_ipv4(host_or_cmd, interval, interface.clone())
Expand Down