From 5ef2ffa34932f4275a33928cccca5f7802bc842e Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Mon, 9 Oct 2023 13:21:51 +0800 Subject: [PATCH] Wait 1 millisecond between duplicate packets Based on my testing, we need to insert 1 millisecond delay between the Original and Duplicate Packets to eliminate the TFTP Timeouts. __Without Delay:__ U-Boot JH7110 boots slower (5.7 Mbps), with 2 TFTP Timeouts ```text Filename 'initrd'. Loading: 711.9 KiB/s Bytes transferred = 8100864 (7b9c00 hex) ``` __With Delay (1 millisecond):__ U-Boot JH7110 boots faster (8.8 Mbps), with No TFTP Timeouts ```text Filename 'initrd'. Loading: 1.1 MiB/s Bytes transferred = 8100864 (7b9c00 hex) ``` --- src/worker.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/worker.rs b/src/worker.rs index 6fd4801..50163de 100644 --- a/src/worker.rs +++ b/src/worker.rs @@ -9,6 +9,7 @@ use std::{ const MAX_RETRIES: u32 = 6; const TIMEOUT_BUFFER: Duration = Duration::from_secs(1); +const DEFAULT_DUPLICATE_DELAY: Duration = Duration::from_millis(1); /// Worker `struct` is used for multithreaded file sending and receiving. /// It creates a new socket using the Server's IP and a random port @@ -241,7 +242,10 @@ impl Worker { } fn send_packet(&self, packet: &Packet) -> Result<(), Box> { - for _ in 0..self.repeat_amount { + for i in 0..self.repeat_amount { + if i > 0 { + std::thread::sleep(DEFAULT_DUPLICATE_DELAY); + } self.socket.send(packet)?; }