even better reliability
This commit is contained in:
parent
7a182731d3
commit
b3933dd478
3 changed files with 12 additions and 9 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -4,4 +4,4 @@ version = 3
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "qft"
|
name = "qft"
|
||||||
version = "0.4.5"
|
version = "0.4.6"
|
||||||
|
|
|
@ -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
|
||||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -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...");
|
||||||
loop {
|
|
||||||
let buf = self
|
let buf = self
|
||||||
.last_transmitted
|
.last_transmitted
|
||||||
.get(&idn)
|
.get(&idn)
|
||||||
.expect("Unable to recover from connection loss.");
|
.expect("Unable to recover from connection loss.");
|
||||||
|
loop {
|
||||||
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;
|
||||||
|
|
Loading…
Reference in a new issue