Implement the skeleton for the Server Session handling

This commit is contained in:
2024-02-15 18:01:47 +01:00
parent 37c76aba22
commit f8feb9db81
6 changed files with 317 additions and 71 deletions

View File

@@ -175,22 +175,46 @@ async fn main() -> std::io::Result<()> {
}
}
// Subscribe consume
transport.for_each(|item| async move {
match item {
Ok(buf) => {
use ToServerMessage::*;
let msg: ToServerMessage = rmp_serde::from_slice(&buf).unwrap();
match msg {
Required { id } => {
info!("I'm required with Connection ID {}", id);
loop {
match transport.next().await {
None => {
info!("Empty Buffer");
}
Some(item) => {
let mut out: Option<FromServerReply> = None;
match item {
Ok(buf) => {
use ToServerMessage::*;
let msg: ToServerMessage = rmp_serde::from_slice(&buf).unwrap();
match msg {
Msg { reply_id, body } => {
use ToServerMessageBody::*;
match body {
Required { id } => {
info!("I'm required with Connection ID {}", id);
out = Some(FromServerReply::Msg {
reply_id,
body: FromServerReplyBody::RequiredAccepted,
})
}
}
}
Ping => {
info!("Ping!");
out = Some(FromServerReply::Pong);
}
}
}
Err(e) => {
error!("Error: {:?}", e);
}
}
}
Err(e) => {
error!("Error: {:?}", e);
if let Some(msg) = out {
transport.send(rmp_serde::to_vec(&msg).unwrap().into()).await.unwrap();
}
}
}
}).await;
}
}
Ok(())
}