Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cbiffle committed Jan 26, 2024
1 parent b03ff98 commit 660ca4f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 19 additions & 7 deletions task/gimlet-inspector/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
#![no_std]
#![no_main]

use core::sync::atomic::{AtomicUsize, Ordering};
use drv_gimlet_seq_api::{SeqError, Sequencer};
use gimlet_inspector_protocol::{
QueryV0, Request, SequencerRegistersResponseV0,
QueryV0, Request, SequencerRegistersResponseV0, ANY_RESPONSE_V0_MAX_SIZE,
REQUEST_TRAILER,
};
use hubpack::SerializedSize;
use task_net_api::*;
Expand All @@ -20,8 +22,12 @@ use userlib::*;
task_slot!(NET, net);
task_slot!(SEQ, seq);

// Increase this if a new message requires a larger trailer.
const MAX_REQ_TRAILER_SIZE: usize = 0;
#[no_mangle]
static CTR_RECVD: AtomicUsize = AtomicUsize::new(0);
#[no_mangle]
static CTR_REJECTED: AtomicUsize = AtomicUsize::new(0);
#[no_mangle]
static CTR_RESPONSES: AtomicUsize = AtomicUsize::new(0);

#[export_name = "main"]
fn main() -> ! {
Expand All @@ -34,17 +40,20 @@ fn main() -> ! {
loop {
// These buffers are currently kept kinda small because our protocol
// messages are small.
let mut rx_data_buf = [0u8; Request::MAX_SIZE + MAX_REQ_TRAILER_SIZE];
let mut tx_data_buf = [0u8; 128];
let mut rx_data_buf = [0u8; Request::MAX_SIZE + REQUEST_TRAILER];
let mut tx_data_buf = [0u8; ANY_RESPONSE_V0_MAX_SIZE];

match net.recv_packet(
SOCKET,
LargePayloadBehavior::Discard,
&mut rx_data_buf,
) {
Ok(mut meta) => {
CTR_RECVD.fetch_add(1, Ordering::Relaxed);

let Ok((request, _trailer)) = hubpack::deserialize::<Request>(&rx_data_buf) else {
// We ignore malformatted, truncated, etc. packets.
CTR_REJECTED.fetch_add(1, Ordering::Relaxed);
continue;
};

Expand Down Expand Up @@ -87,7 +96,10 @@ fn main() -> ! {
meta,
&tx_data_buf[0..(meta.size as usize)],
) {
Ok(()) => break,
Ok(()) => {
CTR_RESPONSES.fetch_add(1, Ordering::Relaxed);
break;
}
// If `net` just restarted, immediately retry our send.
Err(SendError::ServerRestarted) => continue,
// If our tx queue is full, wait for space. This is the
Expand All @@ -111,7 +123,7 @@ fn main() -> ! {
Err(SendError::NotYours | SendError::InvalidVLan) => {
unreachable!()
}
// Unclear under what conditions we could se `Other` -
// Unclear under what conditions we could sse `Other` -
// just panic for now? At the time of this writing
// `Other` should only come back if the destination
// address in `meta` is bogus or our socket is closed,
Expand Down

0 comments on commit 660ca4f

Please sign in to comment.