From 4a1593801a6237baaf629fe20e90feaf47a02e8a Mon Sep 17 00:00:00 2001 From: Xiretza Date: Fri, 17 Jun 2022 20:52:07 +0200 Subject: [PATCH] fix(sender): interpret all errors in confirmation recv as timeout --- src/sender.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/sender.rs b/src/sender.rs index e2a36c3..3dcb9ea 100644 --- a/src/sender.rs +++ b/src/sender.rs @@ -1,7 +1,4 @@ -use std::{ - io::{self, ErrorKind}, - net::UdpSocket, -}; +use std::{io, net::UdpSocket}; use image::{Rgb, RgbImage}; use thiserror::Error; @@ -73,12 +70,9 @@ pub fn send_frame( } let mut buf = vec![0; 100]; - let len = match socket.recv(&mut buf) { - Ok(len) => len, - //Err(e) if e.kind() == ErrorKind::TimedOut => return Err(SenderError::ConfirmationTimeout), - Err(e) => return Err(SenderError::ConfirmationTimeout), - Err(e) => return Err(SenderError::Io(e)), - }; + let len = socket + .recv(&mut buf) + .map_err(|_| SenderError::ConfirmationTimeout)?; let buf = &buf[..len]; let response_frame_num = u32::from_be_bytes( buf.try_into()