Skip to content

Commit

Permalink
even better reliability
Browse files Browse the repository at this point in the history
  • Loading branch information
TudbuT committed Aug 20, 2022
1 parent 7a18273 commit b3933dd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 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.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "qft"
version = "0.4.5"
version = "0.4.6"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
17 changes: 10 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,16 @@ impl SafeReadWrite {
break;
}
let mut buf = [0, 0, 0];
let mut wait = idn == 0xffff || flush;
if self.last_transmitted.len() < 100 {
self.socket
.set_read_timeout(Some(Duration::from_millis(1)))
.unwrap();
}
let mut wait = idn == 0xffff || flush;
let start = unix_millis();
else {
wait = true;
}
let mut start = unix_millis();
if idn == 0xffff {
print!("\r\x1b[KPacket ID needs to wrap. Waiting for partner to catch up...")
}
Expand Down Expand Up @@ -220,11 +223,11 @@ impl SafeReadWrite {
None => {
if unix_millis() - start > 10000 {
println!("\r\x1b[K10s passed since last packet ==> Contact broke. Trying to resend packet...");
let buf = self
.last_transmitted
.get(&idn)
.expect("Unable to recover from connection loss.");
loop {
let buf = self
.last_transmitted
.get(&idn)
.expect("Unable to recover from connection loss.");
match self.socket.send(buf) {
Ok(x) => {
if x != buf.len() {
Expand All @@ -237,7 +240,7 @@ impl SafeReadWrite {
}
break;
}
break;
start = unix_millis();
}
if !wait {
break;
Expand Down

0 comments on commit b3933dd

Please sign in to comment.