fix various bugs related to UDP; prep for transition to libstd-only UDP

This commit is contained in:
bunnie 2022-04-05 00:39:56 +08:00
parent 067c603e03
commit cbb1e3f944
3 changed files with 29 additions and 7 deletions

View file

@ -196,7 +196,7 @@ pub(crate) enum Opcode {
///
/// # Returns
///
/// u16 array
/// u8 array
/// -------|---------
/// offset | Contents
/// =======|=========

View file

@ -471,7 +471,7 @@ fn xmain() -> ! {
}),
Some(Opcode::StdTcpConnect) => {
// Pick a random locak port using the system's TRNG
// Pick a random local port using the system's TRNG
let local_port = (trng.get_u32().unwrap() % 16384 + 49152) as u16;
let pid = msg.sender.pid();
@ -482,6 +482,13 @@ fn xmain() -> ! {
&mut tcp_connect_waiting,
process_sockets.entry(pid).or_default(),
);
xous::try_send_message(
net_conn,
Message::new_scalar(
Opcode::NetPump.to_usize().unwrap(),
0, 0, 0, 0
),
).ok();
}
Some(Opcode::StdTcpTx) => {
@ -493,6 +500,13 @@ fn xmain() -> ! {
&mut tcp_tx_waiting,
process_sockets.entry(pid).or_default(),
);
xous::try_send_message(
net_conn,
Message::new_scalar(
Opcode::NetPump.to_usize().unwrap(),
0, 0, 0, 0
),
).ok();
}
Some(Opcode::StdTcpPeek) => {
@ -1025,6 +1039,13 @@ fn xmain() -> ! {
&mut sockets,
process_sockets.entry(pid).or_default(),
);
xous::try_send_message(
net_conn,
Message::new_scalar(
Opcode::NetPump.to_usize().unwrap(),
0, 0, 0, 0
),
).ok();
}
Some(Opcode::StdUdpClose) => {
@ -1815,7 +1836,6 @@ fn xmain() -> ! {
if let Some(delay) = iface.poll_delay(&sockets, timestamp) {
let delay_ms = delay.total_millis();
if delay_ms < 2 {
log::info!("immediate pump");
xous::try_send_message(
net_conn,
Message::new_scalar(Opcode::NetPump.to_usize().unwrap(), 0, 0, 0, 0),
@ -1824,7 +1844,7 @@ fn xmain() -> ! {
} else {
if delay_threads.load(Ordering::SeqCst) < MAX_DELAY_THREADS {
let prev_count = delay_threads.fetch_add(1, Ordering::SeqCst);
log::info!(
log::trace!(
"spawning checkup thread for {}ms. New total threads: {}",
delay_ms,
prev_count + 1

View file

@ -58,10 +58,10 @@ pub(crate) fn std_udp_bind(
let handle = sockets.add(udp_socket);
// Add the socket into our process' list of sockets, and pass the index back as the `fd` parameter for future reference.
let idx = insert_or_append(our_sockets, handle) as u16;
let idx = insert_or_append(our_sockets, handle) as u8;
let body = msg.body.memory_message_mut().unwrap();
let bfr = body.buf.as_slice_mut::<u16>();
let bfr = body.buf.as_slice_mut::<u8>();
log::trace!("successfully connected: {}", idx);
bfr[0] = 0;
bfr[1] = idx;
@ -107,7 +107,7 @@ pub(crate) fn std_udp_rx(
None
};
let do_peek = body.offset.is_some();
log::trace!("udp rx from fd {}", connection_handle_index);
let mut socket = sockets.get::<UdpSocket>(*handle);
if socket.can_recv() {
log::trace!("receiving data right away");
@ -190,6 +190,7 @@ pub(crate) fn std_udp_tx(
};
let len = u16::from_le_bytes([bytes[19], bytes[20]]);
// attempt the tx
log::trace!("udp tx to fd {}", connection_handle_index);
let mut socket = sockets.get::<UdpSocket>(*handle);
match socket.send_slice(&bytes[21..21 + len as usize], IpEndpoint::new(address, remote_port)) {
Ok(_) => {
@ -198,6 +199,7 @@ pub(crate) fn std_udp_tx(
Err(_e) => {
// the only type of error returned from smoltcp in this case is if the destination is not addressible.
udp_failure(msg, NetError::Unaddressable);
return;
}
}
}