From 21e6a50e36cd8a7ffc1e98ea97e2d19cd9e8950a Mon Sep 17 00:00:00 2001 From: Arkitu <85173315+Arkitu@users.noreply.github.com> Date: Mon, 5 May 2025 22:08:48 +0200 Subject: [PATCH] save --- src/apps/chat.rs | 6 ++++-- src/apps/ttt.rs | 2 +- src/main.rs | 4 ++-- src/socket.rs | 9 +++++---- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/apps/chat.rs b/src/apps/chat.rs index 1d381f1..bcbc5c4 100644 --- a/src/apps/chat.rs +++ b/src/apps/chat.rs @@ -14,12 +14,12 @@ use super::App; const MEMORY_SIZE: usize = 16; const USERNAME_MIN_SIZE: usize = 3; const USERNAME_SIZE: usize = 16; -const MSG_SIZE: usize = 256; +const MSG_SIZE: usize = 128; static MESSAGES: Mutex = Mutex::new(Messages::new()); pub struct ChatApp { - res_buf: Vec, + res_buf: Vec, } impl ChatApp { pub fn new() -> Self { @@ -72,7 +72,9 @@ impl App for ChatApp { username = Some(name); } Some(("msg", m)) => { + info!("raw_msg: {}", m); let mut msg = String::::new(); + // TODO: fix this (maybe do it by hand) for c in percent_decode_str(m) { if let Err(_) = msg.push(c as char) { return (HttpResCode::BadRequest, "", &[]); diff --git a/src/apps/ttt.rs b/src/apps/ttt.rs index d5d5abe..beee258 100644 --- a/src/apps/ttt.rs +++ b/src/apps/ttt.rs @@ -14,7 +14,7 @@ static TURN: AtomicBool = AtomicBool::new(false); static BOARD: AtomicU32 = AtomicU32::new(0); pub struct TttApp { - res_buf: Vec, + res_buf: Vec, /// State of the board last time it has been sent last_board: u32, team: Team, diff --git a/src/main.rs b/src/main.rs index c11654a..05a52b7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -115,7 +115,7 @@ async fn main(spawner: Spawner) { let seed = rng.next_u64(); // Init network stack - static RESOURCES: StaticCell> = StaticCell::new(); + static RESOURCES: StaticCell> = StaticCell::new(); let (stack, runner) = embassy_net::new( net_device, config, @@ -172,7 +172,7 @@ async fn main(spawner: Spawner) { unwrap(spawner.spawn(socket::index_listen_task(stack, 80))).await; unwrap(spawner.spawn(socket::ttt_listen_task(stack, apps::ttt::Team::Zero, 8080))).await; unwrap(spawner.spawn(socket::ttt_listen_task(stack, apps::ttt::Team::One, 8081))).await; - for _ in 0..2 { + for _ in 0..4 { unwrap(spawner.spawn(socket::chat_listen_task(stack, 8082))).await; } } diff --git a/src/socket.rs b/src/socket.rs index 1601c4f..bf2fb80 100644 --- a/src/socket.rs +++ b/src/socket.rs @@ -18,7 +18,7 @@ pub async fn index_listen_task(stack: embassy_net::Stack<'static>, port: u16) { listen_task(stack, IndexApp, port).await } -#[embassy_executor::task(pool_size = 2)] +#[embassy_executor::task(pool_size = 4)] pub async fn chat_listen_task(stack: embassy_net::Stack<'static>, port: u16) { listen_task(stack, chat::ChatApp::new(), port).await } @@ -28,10 +28,10 @@ pub async fn listen_task(stack: embassy_net::Stack<'static>, mut app: impl App, // info!("team:{:?}", team); // Timer::after_millis(0).await; // } - let mut rx_buffer = [0; 8192]; - let mut tx_buffer = [0; 8192]; + let mut rx_buffer = [0; 1024]; + let mut tx_buffer = [0; 2048]; let mut buf = [0; 1024]; - let mut res_head_buf = Vec::::new(); + let mut res_head_buf = Vec::::new(); loop { Timer::after_secs(0).await; @@ -63,6 +63,7 @@ pub async fn listen_task(stack: embassy_net::Stack<'static>, mut app: impl App, break; } }; + info!("{:?}", n); let (headers, content) = match from_utf8(&buf[..n]) { Ok(b) => match b.split_once("\r\n\r\n") {