wip
This commit is contained in:
parent
b37086e8f6
commit
1a13b77295
20 changed files with 767 additions and 468 deletions
29
tun-async/src/tokio/mod.rs
Normal file
29
tun-async/src/tokio/mod.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
use fehler::throws;
|
||||
use std::{
|
||||
io::{self, Error},
|
||||
mem::MaybeUninit,
|
||||
};
|
||||
use tokio::io::unix::AsyncFd;
|
||||
|
||||
pub struct TunQueue {
|
||||
io: AsyncFd<tun::TunQueue>,
|
||||
}
|
||||
|
||||
impl TunQueue {
|
||||
#[throws]
|
||||
pub fn from_queue(queue: tun::TunQueue) -> Self {
|
||||
Self {
|
||||
io: AsyncFd::new(queue)?,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn try_recv(&self, buf: &mut [MaybeUninit<u8>]) -> io::Result<usize> {
|
||||
loop {
|
||||
let mut guard = self.io.readable().await?;
|
||||
match guard.try_io(|inner| inner.get_ref().recv(buf)) {
|
||||
Ok(result) => return result,
|
||||
Err(..) => continue,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue