From 6033a553199d9d132231c15b2e5e09f95d993480 Mon Sep 17 00:00:00 2001 From: Tim Schubert Date: Thu, 7 Nov 2024 14:37:20 +0100 Subject: [PATCH] feat: report failed reads and do not block on empty queuing port --- a653rs-router/src/ports.rs | 17 ++++++++++++----- a653rs-router/src/router.rs | 3 ++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/a653rs-router/src/ports.rs b/a653rs-router/src/ports.rs index c4685ff..7d7d2de 100644 --- a/a653rs-router/src/ports.rs +++ b/a653rs-router/src/ports.rs @@ -36,11 +36,14 @@ impl RouterOutput for SamplingPortSource { impl RouterInput for QueuingPortReceiver { fn receive<'a>(&self, buf: &'a mut [u8]) -> Result<&'a [u8], PortError> { - let timeout = SystemTime::Normal(Duration::from_micros(10)); + const TIMEOUT: SystemTime = SystemTime::Normal(Duration::ZERO); router_bench!(begin_apex_send, self.id() as u16); - let res = self.receive(buf, timeout); + let res = self.receive(buf, TIMEOUT); router_bench!(end_apex_send, self.id() as u16); - let (buf, _overflow) = res.map_err(|_e| PortError::Receive)?; + let (buf, _overflow) = res.map_err(|e| match e { + Error::NotAvailable => PortError::WouldBlock, + _ => PortError::Receive, + })?; Ok(buf) } @@ -51,9 +54,9 @@ impl RouterInput for QueuingPortReceiver { impl RouterOutput for QueuingPortSender { fn send(&self, buf: &[u8]) -> Result<(), PortError> { - let timeout = SystemTime::Normal(Duration::from_micros(10)); + const TIMEOUT: SystemTime = SystemTime::Normal(Duration::ZERO); router_bench!(begin_apex_send, self.id() as u16); - let res = self.send(buf, timeout); + let res = self.send(buf, TIMEOUT); router_bench!(end_apex_send, self.id() as u16); res.map_err(|_e| PortError::Send)?; Ok(()) @@ -67,6 +70,9 @@ impl RouterOutput for QueuingPortSender { /// An error occured while reading or writing a port of the router. #[derive(Clone, Debug, PartialEq, Eq)] pub enum PortError { + /// Operation would block + WouldBlock, + /// Failed to send from router output Send, @@ -83,6 +89,7 @@ impl Display for PortError { Self::Send => write!(f, "Failed to send from router output"), Self::Receive => write!(f, "Failed to receive from router input"), Self::Create => write!(f, "Failed to create router port"), + Self::WouldBlock => write!(f, "Operation would block"), } } } diff --git a/a653rs-router/src/router.rs b/a653rs-router/src/router.rs index 62c3960..5f1bb48 100644 --- a/a653rs-router/src/router.rs +++ b/a653rs-router/src/router.rs @@ -175,7 +175,8 @@ impl<'a, const IN: usize, const OUT: usize> Router<'a, IN, OUT> { router_bench!(begin_virtual_link_scheduled, next.0 as u16); let res = self.routes.route::(&next); router_bench!(end_virtual_link_scheduled, next.0 as u16); - res.map(|_| Some(next)) + res?; + Ok(Some(next)) } else { Ok(None) }