@@ -3,7 +3,7 @@ use std::{borrow::BorrowMut, sync::Arc, collections::HashMap, io::ErrorKind, tim
3
3
use once_cell:: sync:: Lazy ;
4
4
use tokio:: {
5
5
net:: { TcpListener , TcpStream } ,
6
- sync:: Mutex , task:: JoinHandle , time:: sleep,
6
+ sync:: Mutex , task:: JoinHandle , time:: { sleep, timeout } ,
7
7
} ;
8
8
9
9
use crate :: {
@@ -138,20 +138,20 @@ impl Server {
138
138
// Bug: 代理人已经死掉还能写入命令
139
139
let mut agent = agent. lock ( ) . await ;
140
140
let agent = agent. borrow_mut ( ) ;
141
- match write_cmd ( agent, Command :: Nothing , "" ) . await {
141
+ match write_cmd ( agent, Command :: KeepAlive , "" ) . await {
142
142
Err ( _) => {
143
- i ! ( "PORT({port}) -> Agent {agent_addr} offline, release the port!" ) ;
143
+ e ! ( "PORT({port}) -> Agent {agent_addr} offline, release the port!" ) ;
144
144
task. abort ( ) ;
145
145
break ;
146
146
}
147
147
_ => ( )
148
148
}
149
- match read_cmd ( agent, "" ) . await {
150
- Command :: Nothing => {
149
+ match timeout ( Duration :: from_millis ( 2000 ) , read_cmd ( agent, "" ) ) . await {
150
+ Ok ( Command :: KeepAlive ) => {
151
151
// i!("AGENT({agent_addr}) -> Living");
152
152
}
153
153
_ => {
154
- i ! ( "PORT({port}) -> Agent {agent_addr} no response, release the port!" ) ;
154
+ e ! ( "PORT({port}) -> Agent {agent_addr} no response, release the port!" ) ;
155
155
task. abort ( ) ;
156
156
break ;
157
157
}
0 commit comments