net: Reset tcp socks when new eth link is detected

This commit is contained in:
linuswck 2024-04-22 16:01:32 +08:00
parent ba30575406
commit f303ab639a

View File

@ -190,7 +190,7 @@ impl ServerHandle {
}
}
pub fn update_link_speed(&mut self) {
pub fn update_link_speed(&mut self)-> bool {
if !self.link_was_up & self.phy.phy_link_up() {
if let Some(speed) = self.phy.speed().map(|s| match s {
PhySpeed::HalfDuplexBase10T => Speed::HalfDuplexBase10T,
@ -200,11 +200,14 @@ impl ServerHandle {
}) {
info!("New eth link is up. Setting detected PhySpeed: {:?}", speed);
self.phy.get_miim().set_speed(speed);
self.link_was_up = self.phy.phy_link_up();
return true;
} else {
debug!("Failed to detect link speed.");
}
}
self.link_was_up = self.phy.phy_link_up();
return false;
}
pub fn poll_iface(&mut self) {
@ -355,8 +358,14 @@ impl<M: Miim> EthernetPhy<M> {
pub fn eth_poll_link_status_and_update_link_speed() -> bool {
unsafe {
if let Some(ref mut server_handle ) = SERVER_HANDLE {
server_handle.update_link_speed();
return server_handle.link_was_up;
let new_link_is_up = server_handle.update_link_speed();
if new_link_is_up {
info!("Resetting TCP Sockets");
for_each(|socket, _| {
eth_close_socket(socket);
});
}
return new_link_is_up;
}
else {
panic!("eth_poll_link_status_and_update_link_speed is called before init");