This commit is contained in:
Conrad Kramer 2023-04-17 11:58:31 -04:00
parent b37086e8f6
commit 1a13b77295
20 changed files with 767 additions and 468 deletions

View 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,
}
}
}
}