even better reliability

This commit is contained in:
Daniella 2022-08-20 18:55:24 +02:00
parent 7a182731d3
commit b3933dd478
3 changed files with 12 additions and 9 deletions

2
Cargo.lock generated
View file

@ -4,4 +4,4 @@ version = 3
[[package]] [[package]]
name = "qft" name = "qft"
version = "0.4.5" version = "0.4.6"

View file

@ -1,6 +1,6 @@
[package] [package]
name = "qft" name = "qft"
version = "0.4.5" version = "0.4.6"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -154,13 +154,16 @@ impl SafeReadWrite {
break; break;
} }
let mut buf = [0, 0, 0]; let mut buf = [0, 0, 0];
let mut wait = idn == 0xffff || flush;
if self.last_transmitted.len() < 100 { if self.last_transmitted.len() < 100 {
self.socket self.socket
.set_read_timeout(Some(Duration::from_millis(1))) .set_read_timeout(Some(Duration::from_millis(1)))
.unwrap(); .unwrap();
} }
let mut wait = idn == 0xffff || flush; else {
let start = unix_millis(); wait = true;
}
let mut start = unix_millis();
if idn == 0xffff { if idn == 0xffff {
print!("\r\x1b[KPacket ID needs to wrap. Waiting for partner to catch up...") print!("\r\x1b[KPacket ID needs to wrap. Waiting for partner to catch up...")
} }
@ -220,11 +223,11 @@ impl SafeReadWrite {
None => { None => {
if unix_millis() - start > 10000 { if unix_millis() - start > 10000 {
println!("\r\x1b[K10s passed since last packet ==> Contact broke. Trying to resend packet..."); 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 { loop {
let buf = self
.last_transmitted
.get(&idn)
.expect("Unable to recover from connection loss.");
match self.socket.send(buf) { match self.socket.send(buf) {
Ok(x) => { Ok(x) => {
if x != buf.len() { if x != buf.len() {
@ -237,7 +240,7 @@ impl SafeReadWrite {
} }
break; break;
} }
break; start = unix_millis();
} }
if !wait { if !wait {
break; break;