[mio] 路由为空则回收数据
This commit is contained in:
@@ -256,6 +256,17 @@ impl ContextInner {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub fn remove_route(&self, ip: &Ipv4Addr, route_key: RouteKey) {
|
||||
if self.route_table.remove_route(ip, route_key) {
|
||||
if route_key.is_tcp {
|
||||
if let Some(tcp) = self.tcp_map.write().remove(&route_key.addr) {
|
||||
if let Err(e) = tcp.shutdown() {
|
||||
log::warn!("{:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RouteTable {
|
||||
@@ -428,11 +439,18 @@ impl RouteTable {
|
||||
}
|
||||
list
|
||||
}
|
||||
pub fn remove_route(&self, id: &Ipv4Addr, route_key: RouteKey) {
|
||||
if let Some((_, routes)) = self.route_table.write().get_mut(id) {
|
||||
pub fn remove_route(&self, id: &Ipv4Addr, route_key: RouteKey) -> bool {
|
||||
let mut write_guard = self.route_table.write();
|
||||
if let Some((_, routes)) = write_guard.get_mut(id) {
|
||||
routes.retain(|(x, _)| x.route_key() != route_key);
|
||||
if routes.is_empty() {
|
||||
write_guard.remove(id);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/// 更新路由入栈包的时刻,长时间没有收到数据的路由将会被剔除
|
||||
|
||||
@@ -83,7 +83,7 @@ fn idle_route0<Call: VntCallback>(
|
||||
let cur = current_device.load();
|
||||
match idle.next_idle() {
|
||||
IdleType::Timeout(ip, route) => {
|
||||
context.route_table.remove_route(&ip, route);
|
||||
context.remove_route(&ip, route);
|
||||
if cur.is_gateway(&ip) {
|
||||
//网关路由过期,则需要改变状态
|
||||
let cur = context.change_status(current_device);
|
||||
|
||||
Reference in New Issue
Block a user