支持异步tun
This commit is contained in:
@@ -13,6 +13,11 @@ impl Device {
|
|||||||
Ok(Self { fd: Fd::new(fd)? })
|
Ok(Self { fd: Fd::new(fd)? })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl Device {
|
||||||
|
pub fn as_tun_fd(&self) ->&Fd{
|
||||||
|
&self.fd
|
||||||
|
}
|
||||||
|
}
|
||||||
impl IFace for Device {
|
impl IFace for Device {
|
||||||
fn version(&self) -> io::Result<String> {
|
fn version(&self) -> io::Result<String> {
|
||||||
Ok(String::new())
|
Ok(String::new())
|
||||||
|
|||||||
@@ -224,6 +224,11 @@ impl Device {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl Device {
|
||||||
|
pub fn as_tun_fd(&self) ->&Fd{
|
||||||
|
&self.tun
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl IFace for Device {
|
impl IFace for Device {
|
||||||
fn version(&self) -> io::Result<String> {
|
fn version(&self) -> io::Result<String> {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use std::io;
|
use std::io;
|
||||||
use std::os::fd::{AsRawFd, IntoRawFd, RawFd};
|
use std::os::fd::{AsRawFd, IntoRawFd, RawFd};
|
||||||
|
use libc::{F_GETFL, F_SETFL, fcntl, O_NONBLOCK};
|
||||||
|
|
||||||
pub struct Fd(pub RawFd);
|
pub struct Fd(pub RawFd);
|
||||||
|
|
||||||
@@ -10,6 +11,12 @@ impl Fd {
|
|||||||
}
|
}
|
||||||
Ok(Fd(value))
|
Ok(Fd(value))
|
||||||
}
|
}
|
||||||
|
pub fn set_nonblock(&self) -> io::Result<()> {
|
||||||
|
match unsafe { fcntl(self.0, F_SETFL, fcntl(self.0, F_GETFL) | O_NONBLOCK) } {
|
||||||
|
0 => Ok(()),
|
||||||
|
_ => Err(io::Error::last_os_error()),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Fd {
|
impl Fd {
|
||||||
@@ -51,6 +58,7 @@ impl IntoRawFd for Fd {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "android"))]
|
||||||
impl Drop for Fd {
|
impl Drop for Fd {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
mod fd;
|
mod fd;
|
||||||
|
|
||||||
pub use fd::Fd;
|
pub use fd::Fd;
|
||||||
|
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
||||||
use std::process::Output;
|
use std::process::Output;
|
||||||
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
||||||
mod sockaddr;
|
mod sockaddr;
|
||||||
|
|||||||
Reference in New Issue
Block a user