tun增加重试
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
use std::io;
|
use std::{io, thread};
|
||||||
use std::net::Ipv4Addr;
|
use std::net::Ipv4Addr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use libloading::Library;
|
use libloading::Library;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
@@ -75,6 +76,7 @@ pub fn create_tun(
|
|||||||
Ok(lib) => match TunDevice::open(lib, TUN_INTERFACE_NAME) {
|
Ok(lib) => match TunDevice::open(lib, TUN_INTERFACE_NAME) {
|
||||||
Ok(tun_device) => {
|
Ok(tun_device) => {
|
||||||
let _ = tun_device.delete();
|
let _ = tun_device.delete();
|
||||||
|
thread::sleep(Duration::from_millis(5));
|
||||||
}
|
}
|
||||||
Err(_) => {}
|
Err(_) => {}
|
||||||
},
|
},
|
||||||
@@ -92,11 +94,21 @@ pub fn create_tun(
|
|||||||
TUN_INTERFACE_NAME,
|
TUN_INTERFACE_NAME,
|
||||||
) {
|
) {
|
||||||
Ok(tun_device) => tun_device,
|
Ok(tun_device) => tun_device,
|
||||||
Err(e) => {
|
Err(_) => {
|
||||||
return Err(io::Error::new(
|
thread::sleep(Duration::from_millis(200));
|
||||||
io::ErrorKind::Other,
|
match TunDevice::create(
|
||||||
format!("{:?}", e),
|
Library::new("wintun.dll").unwrap(),
|
||||||
));
|
TUN_POOL_NAME,
|
||||||
|
TUN_INTERFACE_NAME,
|
||||||
|
) {
|
||||||
|
Ok(tun_device) => tun_device,
|
||||||
|
Err(e) => {
|
||||||
|
return Err(io::Error::new(
|
||||||
|
io::ErrorKind::Other,
|
||||||
|
format!("{:?}", e),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
println!("name:{:?}", tun_device.get_name()?);
|
println!("name:{:?}", tun_device.get_name()?);
|
||||||
|
|||||||
Reference in New Issue
Block a user