use std::time::Duration;
use crate::{config::util::*, util::IANA_RECOMMEND_DYNAMIC_PORT_RANGE_START};
#[cfg(feature = "mdns")]
pub mod mdns;
#[derive(Debug, Args)]
#[command(arg_required_else_help = true)]
pub struct SendArgs {
#[command(subcommand)]
pub subcmd: SendCommand,
#[arg(
short,
long,
global(true),
value_name("FILE"),
group("io-content"),
name("INPUT_FILE")
)]
pub file: Vec<PathBuf>,
#[arg(long,action = ArgAction::SetTrue, requires = "INPUT_FILE", global(true))]
pub no_prealloc: bool,
#[arg(long, action = ArgAction::SetTrue, requires = "INPUT_FILE", global(true))]
pub mmap: bool,
#[arg(
long("poll"),
global(true),
value_name("INTERVAL_MS"),
default_value_t = 100
)]
pub poll: u32,
#[arg(
long("one-shot"),
visible_alias("disable-poll"),
default_value_t = false
)]
pub one_shot: bool,
#[arg(long, default_value = Some("5000"), group("tcp_about_condition"))]
pub tcp_timeout_ms: Option<u32>,
#[arg(long, group("tcp_about_condition"))]
pub tcp_max_attempts: Option<u32>,
}
impl SendArgs {
pub fn tcp_connect_mode(&self) -> TcpConnectMode {
if self.one_shot {
TcpConnectMode::OneShot
} else {
let abort_cond = if let Some(attempts) = self.tcp_max_attempts {
PollAbortCondition::Attempts(attempts)
} else {
PollAbortCondition::Timeout(Duration::from_millis(
self.tcp_timeout_ms.unwrap().into(),
))
};
TcpConnectMode::poll_from_ms(self.poll, abort_cond)
}
}
pub fn prealloc(&self) -> bool {
if self.file.is_empty() {
false
} else {
!self.no_prealloc
}
}
}
#[allow(clippy::large_enum_variant)] #[derive(Subcommand, Debug)]
pub enum SendCommand {
Ip(SendIpArgs),
#[cfg(feature = "mdns")]
Mdns(mdns::SendMdnsArgs),
}
#[derive(Debug, Args, Clone)]
#[command(flatten_help = true)]
pub struct SendIpArgs {
pub ip: String,
#[arg(short, long, default_value_t = IANA_RECOMMEND_DYNAMIC_PORT_RANGE_START, value_parser = clap::value_parser!(u16).range(1..))]
pub port: u16,
#[command(subcommand)]
pub compression: Option<Compression>,
}