diff --git a/src/bin/rnp/rnp_cli_options.rs b/src/bin/rnp/rnp_cli_options.rs index 623648c..a0c698d 100644 --- a/src/bin/rnp/rnp_cli_options.rs +++ b/src/bin/rnp/rnp_cli_options.rs @@ -28,11 +28,11 @@ pub struct RnpCliOptions { #[derive(Debug, StructOpt, PartialEq)] pub struct RnpCliCommonOptions { - #[structopt(parse(try_from_str = parse_ping_target), help = "Target endpoint. For IPv6, please use [] to wrap the address, such as [::1]:80.")] - pub target: SocketAddr, - #[structopt(short = "m", long = "mode", default_value = "TCP", help = "Specify protocol to use.")] pub protocol: RnpSupportedProtocol, + + #[structopt(parse(try_from_str = parse_ping_target), help = "Target endpoint. For IPv6, please use [] to wrap the address, such as [::1]:80.")] + pub target: SocketAddr, } #[derive(Debug, StructOpt, PartialEq)] diff --git a/src/ping_runners/ping_clients/ping_client_tcp.rs b/src/ping_runners/ping_clients/ping_client_tcp.rs index 18fdafc..5ae357c 100644 --- a/src/ping_runners/ping_clients/ping_client_tcp.rs +++ b/src/ping_runners/ping_clients/ping_client_tcp.rs @@ -111,7 +111,7 @@ mod tests { protocol: RnpSupportedProtocol::TCP, server_address: "127.0.0.1:11337".parse().unwrap(), close_on_accept: false, - sleep_before_write: Duration::from_millis(0), + sleep_before_write: Some(Duration::from_millis(0)), write_chunk_size: 1024, write_count_limit: Some(0), report_interval: Duration::from_secs(1), diff --git a/src/rnp_config.rs b/src/rnp_config.rs index 1d1be96..a6cdf4f 100644 --- a/src/rnp_config.rs +++ b/src/rnp_config.rs @@ -174,7 +174,7 @@ pub struct RnpStubServerConfig { pub protocol: RnpSupportedProtocol, pub server_address: SocketAddr, pub close_on_accept: bool, - pub sleep_before_write: Duration, + pub sleep_before_write: Option, pub write_chunk_size: usize, pub write_count_limit: Option, pub report_interval: Duration, diff --git a/src/stub_servers/stub_server_tcp.rs b/src/stub_servers/stub_server_tcp.rs index a747490..118e790 100644 --- a/src/stub_servers/stub_server_tcp.rs +++ b/src/stub_servers/stub_server_tcp.rs @@ -211,6 +211,10 @@ impl StubServerTcpConnection { #[tracing::instrument(name = "TCP connection on write", level = "debug", skip(self), fields(id = %self.id, remote_address = %self.remote_address))] async fn on_connection_write(&mut self) -> Result<(), Box> { + if let Some(sleep_before_write) = self.config.sleep_before_write { + tokio::time::sleep(sleep_before_write).await; + } + // Update write count { let mut conn_stats = self.conn_stats.lock().unwrap();