fix a rare connection glitch

This commit is contained in:
Daniella / Tove 2022-08-23 10:06:09 +02:00
parent bd3e770a0d
commit 2a675aa9d5
2 changed files with 17 additions and 17 deletions

View file

@ -204,11 +204,11 @@ pub fn gui() -> Result<(), iui::UIError> {
let uib = uib1.clone(); let uib = uib1.clone();
let barb = barb1.clone(); let barb = barb1.clone();
uib1.get().queue_main(move || { uib1.get().queue_main(move || {
let percentage = (f * 100 as f32) as u32; let percentage = (f * 100 as f32) as i32;
if percentage != *lpb1.get() { if percentage != *lpb1.get() {
barb.get().set_value( barb.get().set_value(
uib.get(), uib.get(),
ProgressBarValue::Determinate(percentage), ProgressBarValue::Determinate(percentage as u32),
); );
*lpb1.get() = percentage; *lpb1.get() = percentage;
} }
@ -240,11 +240,11 @@ pub fn gui() -> Result<(), iui::UIError> {
let uib = uib1.clone(); let uib = uib1.clone();
let barb = barb1.clone(); let barb = barb1.clone();
uib1.get().queue_main(move || { uib1.get().queue_main(move || {
let percentage = (f * 100 as f32) as u32; let percentage = (f * 100 as f32) as i32;
if percentage != *lpb1.get() { if percentage != *lpb1.get() {
barb.get().set_value( barb.get().set_value(
uib.get(), uib.get(),
ProgressBarValue::Determinate(percentage), ProgressBarValue::Determinate(percentage as u32),
); );
*lpb1.get() = percentage; *lpb1.get() = percentage;
} }

View file

@ -226,10 +226,7 @@ impl SafeReadWrite {
} }
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 if let Some(buf) = self.last_transmitted.get(&idn) {
.last_transmitted
.get(&idn)
.expect("Unable to recover from connection loss.");
loop { loop {
match self.socket.send(buf) { match self.socket.send(buf) {
Ok(x) => { Ok(x) => {
@ -244,6 +241,9 @@ impl SafeReadWrite {
break; break;
} }
start = unix_millis(); start = unix_millis();
} else {
break; // Latest packet was already ACK'd ==> No packets properly lost ==> Can continue with next packet.
}
} }
if !wait { if !wait {
break; break;