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