From 635ec315f7a809138b743a55af68d701ae9fdd18 Mon Sep 17 00:00:00 2001 From: lbl8603 <49143209+lbl8603@users.noreply.github.com> Date: Wed, 24 Apr 2024 23:02:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0udp=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnt/src/ip_proxy/udp_proxy.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/vnt/src/ip_proxy/udp_proxy.rs b/vnt/src/ip_proxy/udp_proxy.rs index b93d5a5..e416aee 100644 --- a/vnt/src/ip_proxy/udp_proxy.rs +++ b/vnt/src/ip_proxy/udp_proxy.rs @@ -126,6 +126,12 @@ fn udp_proxy( //所有事件 50分钟超时 if let Err(e) = poll.poll(&mut events, Some(Duration::from_secs(50 * 60))) { if e.kind() == io::ErrorKind::TimedOut || e.kind() == io::ErrorKind::WouldBlock { + log::warn!( + "超时清理所有udp映射 {},token_map={},udp_map={}", + e, + token_map.len(), + udp_map.len() + ); token_map.clear(); udp_map.clear(); continue; @@ -198,6 +204,12 @@ fn check_handle( for token in remove_list { if let Some((_, src_addr, _)) = token_map.remove(&token) { udp_map.remove(&src_addr); + log::warn!( + "超时清理udp映射 {},token_map={},udp_map={}", + src_addr, + token_map.len(), + udp_map.len() + ); } } } @@ -246,11 +258,10 @@ fn server_handle( log::error!("register失败:{:?},addr={:?}", e, dest_addr); continue; } - if dest_udp.send(&buf[..len]).is_ok() { - let dest_udp = Rc::new(dest_udp); - token_map.insert(token, (dest_udp.clone(), src_addr, Instant::now())); - udp_map.insert(src_addr, (dest_udp, Instant::now())); - } + let _ = dest_udp.send(&buf[..len]); + let dest_udp = Rc::new(dest_udp); + token_map.insert(token, (dest_udp.clone(), src_addr, Instant::now())); + udp_map.insert(src_addr, (dest_udp, Instant::now())); } Err(e) => { log::error!("绑定目标地址失败:{:?}", e); @@ -304,6 +315,7 @@ fn readable_handle( if len == 0 { return Err(io::Error::from(io::ErrorKind::UnexpectedEof)); } + let _ = udp.send_to(&buf[..len], (*src_addr).into()); } *time = Instant::now();