From 79670a6f9cdd3b496ba00453fa9d3029912e9585 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Sun, 14 Aug 2022 16:40:11 +0200 Subject: [PATCH] better ping printing --- Cargo.lock | 2 +- Cargo.toml | 3 ++- Cross.toml | 2 ++ src/main.rs | 10 +++++----- 4 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 Cross.toml diff --git a/Cargo.lock b/Cargo.lock index 6e1983d..091132c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,4 +4,4 @@ version = 3 [[package]] name = "qft" -version = "0.1.9" +version = "0.1.10" diff --git a/Cargo.toml b/Cargo.toml index 054891e..7caf7df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,9 @@ [package] name = "qft" -version = "0.1.9" +version = "0.1.10" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] + diff --git a/Cross.toml b/Cross.toml new file mode 100644 index 0000000..96141df --- /dev/null +++ b/Cross.toml @@ -0,0 +1,2 @@ +[target.x86_64-apple-darwin] +image = "ghcr.io/cross-rs/x86_64-apple-darwin-cross:local" diff --git a/src/main.rs b/src/main.rs index a0af383..1069171 100644 --- a/src/main.rs +++ b/src/main.rs @@ -247,10 +247,11 @@ fn sender(args: &Vec) { return; } + let m = unix_millis(); sc.write_safe(&buf[..read]).expect("send error"); bytes_sent += read as u64; if (bytes_sent % (br * 20) as u64) < (br as u64) { - print!("\rSent {} bytes", bytes_sent); + print!("\r\x1b[KSent {} bytes with ping {}", bytes_sent, unix_millis() - m); stdout().flush().unwrap(); } } @@ -280,10 +281,11 @@ fn receiver(args: &Vec) { return; } + let m = unix_millis(); file.write(buf).expect("write error"); bytes_received += len as u64; if (bytes_received % (br * 20) as u64) < (br as u64) { - print!("\rReceived {} bytes", bytes_received); + print!("\r\x1b[KReceived {} bytes with ping {}", bytes_received, unix_millis() - m); stdout().flush().unwrap(); } } @@ -334,13 +336,11 @@ fn holepunch(args: &Vec) -> UdpSocket { println!("Waiting..."); let mut stop = false; while !stop { - let m = unix_millis(); - thread::sleep(Duration::from_millis(500 - (m % 500))); + thread::sleep(Duration::from_millis(500 - (unix_millis() % 500))); println!("CONNECT {}", unix_millis()); holepunch.send(&[0]).expect("connection failed"); let result = holepunch.recv(&mut [0, 0]); if result.is_ok() && result.unwrap() == 1 { - println!("Ping: {}", unix_millis() - m); holepunch.send(&[0, 0]).expect("connection failed"); let result = holepunch.recv(&mut [0, 0]); if result.is_ok() && result.unwrap() == 2 {