Commit a8e1f401 by qlintonger xeno

cancel-call和call成功,但是出现死锁问题,卡顿在step - 0这里

parent 19bee953
......@@ -28,14 +28,20 @@ pub(crate) async fn handle_client(
let must_existed_params = ["deviceID", "fromID", "wsPwd"];
let mut connection_params = None;
let ws_stream =
match handle_websocket_handshake(stream, &must_existed_params, STATIC_WS_PWD, &mut connection_params).await {
Ok(ws) => ws,
Err(e) => {
println!("WebSocket握手失败: {:?}", e);
return Ok(());
}
};
let ws_stream = match handle_websocket_handshake(
stream,
&must_existed_params,
STATIC_WS_PWD,
&mut connection_params,
)
.await
{
Ok(ws) => ws,
Err(e) => {
println!("WebSocket握手失败: {:?}", e);
return Ok(());
}
};
let (mut sender, mut receiver) = ws_stream.split();
let mut last_heartbeat_time = Instant::now(); // 包装为 Arc<Mutex<Instant>>
......@@ -83,7 +89,11 @@ pub(crate) async fn handle_client(
}
ClientMessage::SendClientMessage(from_id, client_message, close) => {
let real_user_id = from_id.0;
println!("消息中心:==> 收到消息 {:?} 发送给 {}", &client_message, real_user_id.clone());
println!(
"消息中心:==> 收到消息 {:?} 发送给 {}",
&client_message,
real_user_id.clone()
);
if let Err(e) = sender.send(Message::text(client_message)).await {
println!("发送给用户id {} 独立消息失败:{:?}", real_user_id, e);
break;
......@@ -135,6 +145,8 @@ pub(crate) async fn handle_client(
}
}
} else {
// 断开连接之后直接移除即可
event_sender.send(Event::CloseConnection((from_id.clone(), connection_time))).unwrap();
break; // 客户端断开连接
}
}
......@@ -156,9 +168,13 @@ pub(crate) async fn handle_client(
}
// 发送关闭连接事件
event_sender
.send(Event::CloseConnection((from_id.clone(), connection_time)))
.unwrap();
if let Err(e) =
event_sender.send(Event::CloseConnection((from_id.clone(), connection_time)))
{
println!("发送关闭消息到事件中心失败! 原因: {:?}", e);
} else {
println!("发送关闭消息到事件中心成功!");
}
// 等待事件中心调度任务结束
if let Err(e) = event_task.await {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment