Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: report failed reads and do not block on empty queuing port #10

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions a653rs-router/src/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ impl<S: ApexSamplingPortP4> RouterOutput for SamplingPortSource<S> {

impl<Q: ApexQueuingPortP4> RouterInput for QueuingPortReceiver<Q> {
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)
}

Expand All @@ -51,9 +54,9 @@ impl<Q: ApexQueuingPortP4> RouterInput for QueuingPortReceiver<Q> {

impl<Q: ApexQueuingPortP4> RouterOutput for QueuingPortSender<Q> {
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(())
Expand All @@ -67,6 +70,9 @@ impl<Q: ApexQueuingPortP4> RouterOutput for QueuingPortSender<Q> {
/// 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,

Expand All @@ -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"),
}
}
}
3 changes: 2 additions & 1 deletion a653rs-router/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<B>(&next);
router_bench!(end_virtual_link_scheduled, next.0 as u16);
res.map(|_| Some(next))
res?;
Ok(Some(next))
} else {
Ok(None)
}
Expand Down