From b763350a8b2d923387061f1e8e4b6969eebde3e1 Mon Sep 17 00:00:00 2001 From: linuswck Date: Wed, 4 Sep 2024 12:17:55 +0800 Subject: [PATCH] net: disable IRQ when data is being enqueued - This prevents broken json to be sent out due to IRQ --- src/net/net.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/net/net.rs b/src/net/net.rs index b6b3e17..22233f3 100644 --- a/src/net/net.rs +++ b/src/net/net.rs @@ -246,14 +246,16 @@ impl ServerHandle { pub fn send(&mut self, buffer: &mut [u8], num_bytes: usize, socket_handles: SocketHandle) { let socket = self.socket_set.get_mut::(socket_handles); if num_bytes > 0 { - match socket.send_slice(&buffer[..num_bytes]) { - Ok(_) => { - info!("Enqueued {} bytes.", num_bytes); - } - Err(err) => { - info!("Bytes cannot be sent. Error: {:?}", err) - } - }; + cortex_m::interrupt::free(|_| { + match socket.send_slice(&buffer[..num_bytes]) { + Ok(_) => { + info!("Enqueued {} bytes.", num_bytes); + } + Err(err) => { + info!("Bytes cannot be sent. Error: {:?}", err) + } + }; + }); } }