Implement the skeleton for the Server Session handling
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
Reference in New Issue
Block a user