From e2003d8dea878acc75e59566e61332372f8bf7ac Mon Sep 17 00:00:00 2001 From: lubeilin <1791778603@qq.com> Date: Tue, 5 Mar 2024 21:34:51 +0800 Subject: [PATCH] =?UTF-8?q?[mio]=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnt/src/ip_proxy/icmp_proxy.rs | 13 ++++++------- vnt/src/ip_proxy/tcp_proxy.rs | 7 +++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/vnt/src/ip_proxy/icmp_proxy.rs b/vnt/src/ip_proxy/icmp_proxy.rs index 7472927..23fcadd 100644 --- a/vnt/src/ip_proxy/icmp_proxy.rs +++ b/vnt/src/ip_proxy/icmp_proxy.rs @@ -181,13 +181,12 @@ fn recv_handle( log::warn!("加密失败:{}", e); return; } - if context.send_by_id(net_packet.buffer(), &dest_ip).is_err() { - let connect_server = current_device.connect_server; - if let Err(e) = - context.send_default(net_packet.buffer(), connect_server) - { - log::warn!("发送到目标失败:{},{}", e, connect_server); - } + if let Err(e) = context.send_ipv4_by_id( + net_packet.buffer(), + &dest_ip, + current_device.connect_server, + ) { + log::warn!("发送到目标失败:{}", e); } } } diff --git a/vnt/src/ip_proxy/tcp_proxy.rs b/vnt/src/ip_proxy/tcp_proxy.rs index 3d381b5..95aac13 100644 --- a/vnt/src/ip_proxy/tcp_proxy.rs +++ b/vnt/src/ip_proxy/tcp_proxy.rs @@ -300,6 +300,13 @@ fn tcp_connect(src_port: u16, addr: SocketAddr) -> io::Result { { socket.bind(&SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, 0).into())?; } + if let Err(e) = socket.set_tcp_keepalive( + &socket2::TcpKeepalive::new() + .with_time(Duration::from_secs(120)) + .with_interval(Duration::from_secs(10)), + ) { + log::warn!("set_tcp_keepalive err {:?}", e); + } let _ = socket.set_nodelay(false); socket.connect_timeout(&addr.into(), Duration::from_secs(3))?; socket.set_nonblocking(true)?;