Browse Source

handle error

pbs
jake 4 years ago
parent
commit
cd1c30c8eb
  1. 33
      src/common/mainloop/interserver.rs

33
src/common/mainloop/interserver.rs

@ -139,27 +139,32 @@ where
} }
async fn interserver_send_loop<S>(server_id: ServerId, async fn interserver_send_loop<S>(server_id: ServerId,
mut socket: async_std::net::TcpStream,
output_loop_receiver: async_std::sync::Receiver<S>)
mut socket: async_std::net::TcpStream,
output_loop_receiver: async_std::sync::Receiver<S>)
where where
S: Serialize + std::fmt::Debug + Send + 'static, S: Serialize + std::fmt::Debug + Send + 'static,
{ {
async_std::task::spawn(async move { async_std::task::spawn(async move {
loop { loop {
info!("login send loop"); info!("login send loop");
let msg = output_loop_receiver.recv().await.unwrap();
let payload = serde_json::to_string(&msg);
if let Ok(payload) = payload {
let len_bytes = u32::to_le_bytes(payload.len() as u32);
match output_loop_receiver.recv().await {
Ok(msg) => {
let payload = serde_json::to_string(&msg);
if let Ok(payload) = payload {
let len_bytes = u32::to_le_bytes(payload.len() as u32);
match socket.write_all(&len_bytes).await {
Ok(_) => {},
Err(err) => warn!("send failed: {:?}", err),
}
match socket.write_all(&payload.as_bytes()).await {
Ok(_) => {},
Err(err) => warn!("send failed: {:?}", err),
match socket.write_all(&len_bytes).await {
Ok(_) => {},
Err(err) => warn!("send failed: {:?}", err),
}
match socket.write_all(&payload.as_bytes()).await {
Ok(_) => {},
Err(err) => warn!("send failed: {:?}", err),
}
}
},
Err(err) => {
warn!("error in send_loop: {:?}, {:?}", server_id, err)
} }
} }
} }

Loading…
Cancel
Save