save
This commit is contained in:
parent
ea43024446
commit
785671d8cd
@ -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::<BUF_LEN>::new();
|
||||
let mut path = String::<PATH_LEN>::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<String<28>, ()> {
|
||||
let mut res = Vec::<u8, 28>::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) {
|
||||
|
@ -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(()));
|
||||
|
Loading…
Reference in New Issue
Block a user