Update duplicate packet behavior
This commit is contained in:
parent
e8f8c8e8c1
commit
bf7b2a2ee3
3 changed files with 23 additions and 15 deletions
|
|
@ -91,15 +91,20 @@ impl Config {
|
|||
println!(" -d, --directory <DIRECTORY>\tSet the serving directory (default: Current Working Directory)");
|
||||
println!(" -s, --single-port\t\tUse a single port for both sending and receiving (default: false)");
|
||||
println!(" -r, --read-only\t\tRefuse all write requests, making the server read-only (default: false)");
|
||||
println!(" --duplicate-packets <NUM>\tDuplicate all packets sent from the server (default: 1)");
|
||||
println!(" --duplicate-packets <NUM>\tDuplicate all packets sent from the server (default: 0)");
|
||||
println!(" -h, --help\t\t\tPrint help information");
|
||||
process::exit(0);
|
||||
}
|
||||
"--duplicate-packets" => {
|
||||
if let Some(duplicate_packets_str) = args.next() {
|
||||
let duplicate_packets = duplicate_packets_str.parse::<u8>()?;
|
||||
if duplicate_packets < 1 {
|
||||
return Err("Duplicate packets must be greater than 0".into());
|
||||
|
||||
if duplicate_packets == u8::MAX {
|
||||
return Err(format!(
|
||||
"Duplicate packets should be less than {}",
|
||||
u8::MAX
|
||||
)
|
||||
.into());
|
||||
}
|
||||
config.duplicate_packets = duplicate_packets;
|
||||
} else {
|
||||
|
|
@ -178,13 +183,6 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn returns_error_on_invalid_duplicate_packets() {
|
||||
assert!(Config::new(
|
||||
["/", "--duplicate-packets", "0"]
|
||||
.iter()
|
||||
.map(|s| s.to_string()),
|
||||
)
|
||||
.is_err());
|
||||
|
||||
assert!(Config::new(
|
||||
["/", "--duplicate-packets", "-1"]
|
||||
.iter()
|
||||
|
|
@ -192,4 +190,14 @@ mod tests {
|
|||
)
|
||||
.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returns_error_on_max_duplicate_packets() {
|
||||
assert!(Config::new(
|
||||
["/", "--duplicate-packets", format!("{}", u8::MAX).as_str()]
|
||||
.iter()
|
||||
.map(|s| s.to_string()),
|
||||
)
|
||||
.is_err());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ impl Server {
|
|||
worker_options.block_size,
|
||||
worker_options.timeout,
|
||||
worker_options.window_size,
|
||||
self.duplicate_packets,
|
||||
self.duplicate_packets + 1,
|
||||
);
|
||||
worker.send()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ pub struct Worker<T: Socket + ?Sized> {
|
|||
blk_size: usize,
|
||||
timeout: Duration,
|
||||
windowsize: u16,
|
||||
duplicate_packets: u8,
|
||||
repeat_amount: u8,
|
||||
}
|
||||
|
||||
impl<T: Socket + ?Sized> Worker<T> {
|
||||
|
|
@ -54,7 +54,7 @@ impl<T: Socket + ?Sized> Worker<T> {
|
|||
blk_size: usize,
|
||||
timeout: Duration,
|
||||
windowsize: u16,
|
||||
duplicate_packets: u8,
|
||||
repeat_amount: u8,
|
||||
) -> Worker<T> {
|
||||
Worker {
|
||||
socket,
|
||||
|
|
@ -62,7 +62,7 @@ impl<T: Socket + ?Sized> Worker<T> {
|
|||
blk_size,
|
||||
timeout,
|
||||
windowsize,
|
||||
duplicate_packets,
|
||||
repeat_amount,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -241,7 +241,7 @@ impl<T: Socket + ?Sized> Worker<T> {
|
|||
}
|
||||
|
||||
fn send_packet(&self, packet: &Packet) -> Result<(), Box<dyn Error>> {
|
||||
for _ in 0..self.duplicate_packets {
|
||||
for _ in 0..self.repeat_amount {
|
||||
self.socket.send(packet)?;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue