From 785671d8cdaf3640c6902a0c99b3c442aa37b9df Mon Sep 17 00:00:00 2001 From: Arkitu <85173315+Arkitu@users.noreply.github.com> Date: Thu, 28 Aug 2025 14:35:25 +0200 Subject: [PATCH] save --- src/socket.rs | 33 ++++++++++++++++++++------------- src/socket/ws.rs | 3 +++ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/socket.rs b/src/socket.rs index 460dbd1..bfc8dcc 100644 --- a/src/socket.rs +++ b/src/socket.rs @@ -17,18 +17,18 @@ pub mod ws; #[cfg(feature = "ttt")] #[embassy_executor::task(pool_size = 2)] pub async fn ttt_listen_task(stack: embassy_net::Stack<'static>, team: apps::ttt::Team, port: u16) { - listen_task::<32, 32, 256, 256>(stack, apps::ttt::TttApp::new(team), port).await + listen_task::<32, 32, 1024, 256>(stack, apps::ttt::TttApp::new(team), port).await } #[embassy_executor::task(pool_size = 2)] pub async fn index_listen_task(stack: embassy_net::Stack<'static>, port: u16) { - listen_task::<64, 0, 1024, 1024>(stack, apps::index::IndexApp, port).await + listen_task::<64, 0, 2048, 1024>(stack, apps::index::IndexApp, port).await } #[cfg(feature = "chat")] #[embassy_executor::task(pool_size = 4)] pub async fn chat_listen_task(stack: embassy_net::Stack<'static>, id: u8, port: u16) { - listen_task::<64, 512, 512, 512>(stack, apps::chat::ChatApp::new(id), port).await + listen_task::<64, 1024, 1024, 1024>(stack, apps::chat::ChatApp::new(id), port).await } pub async fn listen_task< @@ -61,7 +61,7 @@ pub async fn listen_task< socket.remote_endpoint() ); - let (mut rx, mut tx) = socket.split(); + // let (mut rx, mut tx) = socket.split(); let mut buf = String::::new(); let mut path = String::::new(); let mut request_type = HttpRequestType::Get; @@ -69,13 +69,16 @@ pub async fn listen_task< loop { Timer::after_secs(0).await; - match rx + match socket .read_with(|msg| { let (headers, content) = match from_utf8(msg) { - Ok(b) => match b.split_once("\r\n\r\n") { - Some(t) => t, - None => (b, ""), - }, + Ok(b) => { + info!("{}", b); + match b.split_once("\r\n\r\n") { + Some(t) => t, + None => (b, ""), + } + } Err(_) => { warn!("Non utf8 http request"); return (0, Err(())); @@ -230,10 +233,10 @@ pub async fn listen_task< }; let w: Result<(), embassy_net::tcp::Error> = try { - tx.write_all(&head_buf).await?; + socket.write_all(&head_buf).await?; if let Some(ref c) = res_content { for s in c.0.iter() { - tx.write_all(s.as_bytes()).await?; + socket.write_all(s.as_bytes()).await?; } } }; @@ -242,6 +245,10 @@ pub async fn listen_task< warn!("write error: {:?}", e); break; }; + + if is_ws { + break; + } } if is_ws { let mut buf = buf.into_bytes(); @@ -297,13 +304,13 @@ impl Into<&str> for HttpResCode { fn compute_ws_accept(key: &str) -> Result, ()> { let mut res = Vec::::new(); - res.fill(0); + res.resize_default(28)?; let mut hasher = Sha1::new(); hasher.update(key.as_bytes()); hasher.update(b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"); let hash = hasher.finalize(); if let Err(e) = BASE64_STANDARD.encode_slice(hash, &mut res) { - warn!("Error while base64 encoding : {}", e); + warn!("Error while base64 encoding : {}\nkey: {}", e, key); return Err(()); }; match String::from_utf8(res) { diff --git a/src/socket/ws.rs b/src/socket/ws.rs index ed3467e..a9296fa 100644 --- a/src/socket/ws.rs +++ b/src/socket/ws.rs @@ -67,6 +67,9 @@ impl<'a> WsTx<'a> { ) -> Result<(), ()> { self.socket .write_with(|buf| { + if buf.len() < 6 { + return (0, Err(())); + } buf[0] = 0b1000_0000 | msg_code; let Ok(n) = f(&mut buf[4..]) else { return (0, Err(()));