This commit is contained in:
Arkitu 2025-05-05 22:08:48 +02:00
parent 4521697f48
commit 21e6a50e36
4 changed files with 12 additions and 9 deletions

View File

@ -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<ThreadModeRawMutex, Messages> = Mutex::new(Messages::new());
pub struct ChatApp {
res_buf: Vec<u8, 2048>,
res_buf: Vec<u8, 1100>,
}
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::<MSG_SIZE>::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, "", &[]);

View File

@ -14,7 +14,7 @@ static TURN: AtomicBool = AtomicBool::new(false);
static BOARD: AtomicU32 = AtomicU32::new(0);
pub struct TttApp {
res_buf: Vec<u8, 4096>,
res_buf: Vec<u8, 2048>,
/// State of the board last time it has been sent
last_board: u32,
team: Team,

View File

@ -115,7 +115,7 @@ async fn main(spawner: Spawner) {
let seed = rng.next_u64();
// Init network stack
static RESOURCES: StaticCell<StackResources<10>> = StaticCell::new();
static RESOURCES: StaticCell<StackResources<20>> = 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;
}
}

View File

@ -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::<u8, 1024>::new();
let mut res_head_buf = Vec::<u8, 128>::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") {