From cbb1e3f944f7d9cdb439c2239328d6e2842fd575 Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 5 Apr 2022 00:39:56 +0800 Subject: [PATCH] fix various bugs related to UDP; prep for transition to libstd-only UDP --- services/net/src/api.rs | 2 +- services/net/src/main.rs | 26 +++++++++++++++++++++++--- services/net/src/std_udp.rs | 8 +++++--- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/services/net/src/api.rs b/services/net/src/api.rs index ebb88b1c2..f0a94b13e 100644 --- a/services/net/src/api.rs +++ b/services/net/src/api.rs @@ -196,7 +196,7 @@ pub(crate) enum Opcode { /// /// # Returns /// - /// u16 array + /// u8 array /// -------|--------- /// offset | Contents /// =======|========= diff --git a/services/net/src/main.rs b/services/net/src/main.rs index 7f028891d..1fa0d11a6 100644 --- a/services/net/src/main.rs +++ b/services/net/src/main.rs @@ -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 diff --git a/services/net/src/std_udp.rs b/services/net/src/std_udp.rs index a3499766f..7591583e3 100644 --- a/services/net/src/std_udp.rs +++ b/services/net/src/std_udp.rs @@ -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::(); + let bfr = body.buf.as_slice_mut::(); 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::(*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::(*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; } } }