mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
fix various bugs related to UDP; prep for transition to libstd-only UDP
This commit is contained in:
parent
067c603e03
commit
cbb1e3f944
3 changed files with 29 additions and 7 deletions
|
|
@ -196,7 +196,7 @@ pub(crate) enum Opcode {
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// u16 array
|
/// u8 array
|
||||||
/// -------|---------
|
/// -------|---------
|
||||||
/// offset | Contents
|
/// offset | Contents
|
||||||
/// =======|=========
|
/// =======|=========
|
||||||
|
|
|
||||||
|
|
@ -471,7 +471,7 @@ fn xmain() -> ! {
|
||||||
}),
|
}),
|
||||||
|
|
||||||
Some(Opcode::StdTcpConnect) => {
|
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 local_port = (trng.get_u32().unwrap() % 16384 + 49152) as u16;
|
||||||
let pid = msg.sender.pid();
|
let pid = msg.sender.pid();
|
||||||
|
|
||||||
|
|
@ -482,6 +482,13 @@ fn xmain() -> ! {
|
||||||
&mut tcp_connect_waiting,
|
&mut tcp_connect_waiting,
|
||||||
process_sockets.entry(pid).or_default(),
|
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) => {
|
Some(Opcode::StdTcpTx) => {
|
||||||
|
|
@ -493,6 +500,13 @@ fn xmain() -> ! {
|
||||||
&mut tcp_tx_waiting,
|
&mut tcp_tx_waiting,
|
||||||
process_sockets.entry(pid).or_default(),
|
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) => {
|
Some(Opcode::StdTcpPeek) => {
|
||||||
|
|
@ -1025,6 +1039,13 @@ fn xmain() -> ! {
|
||||||
&mut sockets,
|
&mut sockets,
|
||||||
process_sockets.entry(pid).or_default(),
|
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) => {
|
Some(Opcode::StdUdpClose) => {
|
||||||
|
|
@ -1815,7 +1836,6 @@ fn xmain() -> ! {
|
||||||
if let Some(delay) = iface.poll_delay(&sockets, timestamp) {
|
if let Some(delay) = iface.poll_delay(&sockets, timestamp) {
|
||||||
let delay_ms = delay.total_millis();
|
let delay_ms = delay.total_millis();
|
||||||
if delay_ms < 2 {
|
if delay_ms < 2 {
|
||||||
log::info!("immediate pump");
|
|
||||||
xous::try_send_message(
|
xous::try_send_message(
|
||||||
net_conn,
|
net_conn,
|
||||||
Message::new_scalar(Opcode::NetPump.to_usize().unwrap(), 0, 0, 0, 0),
|
Message::new_scalar(Opcode::NetPump.to_usize().unwrap(), 0, 0, 0, 0),
|
||||||
|
|
@ -1824,7 +1844,7 @@ fn xmain() -> ! {
|
||||||
} else {
|
} else {
|
||||||
if delay_threads.load(Ordering::SeqCst) < MAX_DELAY_THREADS {
|
if delay_threads.load(Ordering::SeqCst) < MAX_DELAY_THREADS {
|
||||||
let prev_count = delay_threads.fetch_add(1, Ordering::SeqCst);
|
let prev_count = delay_threads.fetch_add(1, Ordering::SeqCst);
|
||||||
log::info!(
|
log::trace!(
|
||||||
"spawning checkup thread for {}ms. New total threads: {}",
|
"spawning checkup thread for {}ms. New total threads: {}",
|
||||||
delay_ms,
|
delay_ms,
|
||||||
prev_count + 1
|
prev_count + 1
|
||||||
|
|
|
||||||
|
|
@ -58,10 +58,10 @@ pub(crate) fn std_udp_bind(
|
||||||
let handle = sockets.add(udp_socket);
|
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.
|
// 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 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);
|
log::trace!("successfully connected: {}", idx);
|
||||||
bfr[0] = 0;
|
bfr[0] = 0;
|
||||||
bfr[1] = idx;
|
bfr[1] = idx;
|
||||||
|
|
@ -107,7 +107,7 @@ pub(crate) fn std_udp_rx(
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let do_peek = body.offset.is_some();
|
let do_peek = body.offset.is_some();
|
||||||
|
log::trace!("udp rx from fd {}", connection_handle_index);
|
||||||
let mut socket = sockets.get::<UdpSocket>(*handle);
|
let mut socket = sockets.get::<UdpSocket>(*handle);
|
||||||
if socket.can_recv() {
|
if socket.can_recv() {
|
||||||
log::trace!("receiving data right away");
|
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]]);
|
let len = u16::from_le_bytes([bytes[19], bytes[20]]);
|
||||||
// attempt the tx
|
// attempt the tx
|
||||||
|
log::trace!("udp tx to fd {}", connection_handle_index);
|
||||||
let mut socket = sockets.get::<UdpSocket>(*handle);
|
let mut socket = sockets.get::<UdpSocket>(*handle);
|
||||||
match socket.send_slice(&bytes[21..21 + len as usize], IpEndpoint::new(address, remote_port)) {
|
match socket.send_slice(&bytes[21..21 + len as usize], IpEndpoint::new(address, remote_port)) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
|
|
@ -198,6 +199,7 @@ pub(crate) fn std_udp_tx(
|
||||||
Err(_e) => {
|
Err(_e) => {
|
||||||
// the only type of error returned from smoltcp in this case is if the destination is not addressible.
|
// the only type of error returned from smoltcp in this case is if the destination is not addressible.
|
||||||
udp_failure(msg, NetError::Unaddressable);
|
udp_failure(msg, NetError::Unaddressable);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue