Skip to content

Commit

Permalink
better ping printing
Browse files Browse the repository at this point in the history
  • Loading branch information
TudbuT committed Aug 14, 2022
1 parent 97b8129 commit 79670a6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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]

2 changes: 2 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.x86_64-apple-darwin]
image = "ghcr.io/cross-rs/x86_64-apple-darwin-cross:local"
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,11 @@ fn sender(args: &Vec<String>) {
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();
}
}
Expand Down Expand Up @@ -280,10 +281,11 @@ fn receiver(args: &Vec<String>) {
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();
}
}
Expand Down Expand Up @@ -334,13 +336,11 @@ fn holepunch(args: &Vec<String>) -> 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 {
Expand Down

0 comments on commit 79670a6

Please sign in to comment.