[mio] 优化代理

This commit is contained in:
lubeilin
2024-03-05 21:34:51 +08:00
parent f0a2edadfa
commit e2003d8dea
2 changed files with 13 additions and 7 deletions
+6 -7
View File
@@ -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);
}
}
}
+7
View File
@@ -300,6 +300,13 @@ fn tcp_connect(src_port: u16, addr: SocketAddr) -> io::Result<TcpStream> {
{
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)?;