避免直接关闭网卡
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
||||
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 mod channel;
|
||||
|
||||
@@ -112,16 +112,17 @@ impl DeviceWriter {
|
||||
}
|
||||
}
|
||||
pub fn close(&self) -> io::Result<()> {
|
||||
unsafe {
|
||||
match &self.writer {
|
||||
DeviceW::Tun(writer) => {
|
||||
libc::close(writer.as_raw_fd());
|
||||
}
|
||||
DeviceW::Tap((writer, _)) => {
|
||||
libc::close(writer.as_raw_fd());
|
||||
}
|
||||
}
|
||||
}
|
||||
//早期使用close直接切断网卡,现在并不需要这么做也能正常关闭
|
||||
// unsafe {
|
||||
// match &self.writer {
|
||||
// DeviceW::Tun(writer) => {
|
||||
// libc::close(writer.as_raw_fd());
|
||||
// }
|
||||
// DeviceW::Tap((writer, _)) => {
|
||||
// libc::close(writer.as_raw_fd());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
Ok(())
|
||||
}
|
||||
pub fn is_tun(&self) -> bool {
|
||||
|
||||
@@ -29,5 +29,6 @@ features = [
|
||||
"winerror",
|
||||
"ipexport",
|
||||
"iphlpapi",
|
||||
"handleapi"
|
||||
"handleapi",
|
||||
"ifdef"
|
||||
]
|
||||
@@ -119,7 +119,8 @@ impl TapDevice {
|
||||
}
|
||||
|
||||
pub fn delete(self) -> io::Result<()> {
|
||||
iface::delete_interface(&self.luid)
|
||||
// iface::delete_interface(&self.luid)
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -193,8 +193,8 @@ pub struct Version {
|
||||
|
||||
impl IFace for TunDevice {
|
||||
fn shutdown(&self) -> io::Result<()> {
|
||||
let _ = unsafe { synchapi::SetEvent(self.shutdown_event) };
|
||||
let _ = unsafe { handleapi::CloseHandle(self.shutdown_event) };
|
||||
// let _ = unsafe { synchapi::SetEvent(self.shutdown_event) };
|
||||
// let _ = unsafe { handleapi::CloseHandle(self.shutdown_event) };
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user