[mio] 调整重连

This commit is contained in:
lubeilin
2024-03-10 16:08:17 +08:00
parent 44e379df82
commit 39becec2e5
+13 -9
View File
@@ -67,10 +67,15 @@ fn idle_gateway0<Call: VntCallback>(
call: &Call,
connect_count: &mut usize,
) {
let cur = current_device.load();
if let Err(e) =
check_gateway_channel(context, cur, config, tcp_socket_sender, call, connect_count)
{
if let Err(e) = check_gateway_channel(
context,
current_device,
config,
tcp_socket_sender,
call,
connect_count,
) {
let cur = current_device.load();
call.error(ErrorInfo::new_msg(
ErrorType::Disconnect,
format!("connect:{},error:{:?}", cur.connect_server, e),
@@ -105,16 +110,14 @@ fn idle_route0<Call: VntCallback>(
fn check_gateway_channel<Call: VntCallback>(
context: &Context,
current_device: CurrentDeviceInfo,
current_device: &AtomicCell<CurrentDeviceInfo>,
config: &BaseConfigInfo,
tcp_socket_sender: &AcceptSocketSender<(TcpStream, SocketAddr, Option<Vec<u8>>)>,
call: &Call,
count: &mut usize,
) -> io::Result<()> {
let gateway_route = context
.route_table
.route_one(&current_device.virtual_gateway);
if gateway_route.is_none() {
let current_device = context.change_status(current_device);
if current_device.status.offline() {
*count += 1;
if *count % 4 == 0 {
context.change_main_index();
@@ -122,6 +125,7 @@ fn check_gateway_channel<Call: VntCallback>(
//需要重连
call.connect(ConnectInfo::new(*count, current_device.connect_server));
let request_packet = handshaker::handshake_request_packet(config.client_secret)?;
log::info!("发送握手请求,{:?}", config);
if let Err(e) = context.send_default(request_packet.buffer(), current_device.connect_server)
{
log::warn!("{:?}", e);