避免直接关闭网卡

This commit is contained in:
lubeilin
2023-09-24 12:55:42 +08:00
parent ba69ba78af
commit 00936a923e
5 changed files with 18 additions and 15 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
use crate::error::Error; use crate::error::Error;
pub const VNT_VERSION: &'static str = "1.2.4.3"; pub const VNT_VERSION: &'static str = "1.2.4.4";
pub type Result<T> = std::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, Error>;
pub mod channel; pub mod channel;
+11 -10
View File
@@ -112,16 +112,17 @@ impl DeviceWriter {
} }
} }
pub fn close(&self) -> io::Result<()> { pub fn close(&self) -> io::Result<()> {
unsafe { //早期使用close直接切断网卡,现在并不需要这么做也能正常关闭
match &self.writer { // unsafe {
DeviceW::Tun(writer) => { // match &self.writer {
libc::close(writer.as_raw_fd()); // DeviceW::Tun(writer) => {
} // libc::close(writer.as_raw_fd());
DeviceW::Tap((writer, _)) => { // }
libc::close(writer.as_raw_fd()); // DeviceW::Tap((writer, _)) => {
} // libc::close(writer.as_raw_fd());
} // }
} // }
// }
Ok(()) Ok(())
} }
pub fn is_tun(&self) -> bool { pub fn is_tun(&self) -> bool {
+2 -1
View File
@@ -29,5 +29,6 @@ features = [
"winerror", "winerror",
"ipexport", "ipexport",
"iphlpapi", "iphlpapi",
"handleapi" "handleapi",
"ifdef"
] ]
+2 -1
View File
@@ -119,7 +119,8 @@ impl TapDevice {
} }
pub fn delete(self) -> io::Result<()> { pub fn delete(self) -> io::Result<()> {
iface::delete_interface(&self.luid) // iface::delete_interface(&self.luid)
Ok(())
} }
} }
+2 -2
View File
@@ -193,8 +193,8 @@ pub struct Version {
impl IFace for TunDevice { impl IFace for TunDevice {
fn shutdown(&self) -> io::Result<()> { fn shutdown(&self) -> io::Result<()> {
let _ = unsafe { synchapi::SetEvent(self.shutdown_event) }; // let _ = unsafe { synchapi::SetEvent(self.shutdown_event) };
let _ = unsafe { handleapi::CloseHandle(self.shutdown_event) }; // let _ = unsafe { handleapi::CloseHandle(self.shutdown_event) };
Ok(()) Ok(())
} }