[mio] 调整代码

This commit is contained in:
lubeilin
2024-03-13 21:23:32 +08:00
parent d2c5aac178
commit 8a4d21849e
7 changed files with 52 additions and 25 deletions
+14
View File
@@ -1,3 +1,4 @@
use crossbeam_utils::atomic::AtomicCell;
use std::net::{Ipv4Addr, SocketAddr};
pub mod callback;
@@ -201,3 +202,16 @@ impl CurrentDeviceInfo {
&self.virtual_gateway == ip || ip == &GATEWAY_IP
}
}
pub fn change_status(
current_device: &AtomicCell<CurrentDeviceInfo>,
connect_status: ConnectStatus,
) -> CurrentDeviceInfo {
loop {
let cur = current_device.load();
let mut new_info = cur;
new_info.status = connect_status;
if current_device.compare_exchange(cur, new_info).is_ok() {
return new_info;
}
}
}