解决tcp掉线问题

This commit is contained in:
lubeilin
2024-04-05 23:01:34 +08:00
parent ca91f97c27
commit ee2186aba5
2 changed files with 2 additions and 21 deletions
+2 -15
View File
@@ -289,15 +289,7 @@ impl ContextInner {
}
}
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);
}
}
}
}
self.route_table.remove_route(ip, route_key)
}
}
@@ -501,18 +493,13 @@ impl RouteTable {
}
list
}
pub fn remove_route(&self, id: &Ipv4Addr, route_key: RouteKey) -> bool {
pub fn remove_route(&self, id: &Ipv4Addr, route_key: RouteKey) {
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 true;
}
}
/// 更新路由入栈包的时刻,长时间没有收到数据的路由将会被剔除
-6
View File
@@ -179,9 +179,6 @@ pub fn init_context(
)
};
io_convert(socket.set_reuse_address(true), |_| {
format!("set_reuse_address failed: {}", &address)
})?;
io_convert(socket.set_send_buffer_size(2 * 1024 * 1024), |_| {
format!("set_send_buffer_size failed: {}", &address)
})?;
@@ -220,9 +217,6 @@ pub fn init_context(
(socket, address)
};
io_convert(socket.set_reuse_address(true), |_| {
format!("set_reuse_address failed: {}", &address)
})?;
if let Err(e) = socket.bind(&address.into()) {
if ports[0] == 0 {
//端口可能冲突,则使用任意端口