From 43d674718838bf0bfdf57c964c844256e1454b05 Mon Sep 17 00:00:00 2001 From: Lup Yuen Lee Date: Sun, 8 Oct 2023 16:07:58 +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. __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 3e39e83..bd5c61d 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.duplicate_packets { + for i in 0..self.duplicate_packets { + if i > 0 { + std::thread::sleep(DEFAULT_DUPLICATE_DELAY); + } self.socket.send(packet)?; }