From b683c8a391912133bec068206ad75ef86d6f5250 Mon Sep 17 00:00:00 2001 From: Thomas Kolb Date: Wed, 10 Mar 2021 22:38:30 +0100 Subject: [PATCH] =?UTF-8?q?main:=20handle=20=E2=80=9CConnection=20refused?= =?UTF-8?q?=E2=80=9D=20UDP=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2cb743a..0c24719 100644 --- a/src/main.rs +++ b/src/main.rs @@ -139,15 +139,32 @@ fn main() let strip = i / config::NUM_LEDS_PER_STRIP; let led = i % config::NUM_LEDS_PER_STRIP; - udpproto.set_color(strip as u8, - led as u8, - (colorlists[strip][led].r * 255.0) as u8, - (colorlists[strip][led].g * 255.0) as u8, - (colorlists[strip][led].b * 255.0) as u8, - (colorlists[strip][led].w * 255.0) as u8).unwrap(); + let r = udpproto.set_color(strip as u8, + led as u8, + (colorlists[strip][led].r * 255.0) as u8, + (colorlists[strip][led].g * 255.0) as u8, + (colorlists[strip][led].b * 255.0) as u8, + (colorlists[strip][led].w * 255.0) as u8); + + match r { + Ok(_) => (), + Err(e) if e.kind() == std::io::ErrorKind::ConnectionRefused => { + // try again in one second + next_send_instant += Duration::from_secs(1); + break; + } + Err(e) => panic!(e), + } } - udpproto.commit().unwrap(); + match udpproto.commit() { + Ok(_) => (), + Err(e) if e.kind() == std::io::ErrorKind::ConnectionRefused => { + // try again in one second + next_send_instant += Duration::from_secs(1); + } + Err(e) => panic!(e), + } next_send_instant += send_period; }