Browse Source

handle error

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

37
src/common/mainloop/interserver.rs

@ -139,27 +139,32 @@ where
}
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
S: Serialize + std::fmt::Debug + Send + 'static,
{
async_std::task::spawn(async move {
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 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 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),
}
}
},
Err(err) => {
warn!("error in send_loop: {:?}, {:?}", server_id, err)
}
}
}
@ -179,7 +184,7 @@ pub fn login_listen_mainloop<EG: EntityGateway + 'static>(state: Arc<Mutex<Chara
loop {
let (socket, addr) = listener.accept().await.unwrap();
info!("new ship server: {:?} {:?}", socket, addr);
id += 1;
let server_id = crate::common::interserver::ServerId(id);

Loading…
Cancel
Save