pub struct AsyncStdTun { /* private fields */ }
Expand description
An asynchronous virtual TUN device based on the async-std
/smol
ecosystems.
Implementations§
Source§impl AsyncStdTun
impl AsyncStdTun
Sourcepub fn new(name: &str, num_queues: usize) -> Result<Self>
pub fn new(name: &str, num_queues: usize) -> Result<Self>
Create a new multi-queue async Tun device, supporting the async-std
/smol
ecosystems,
using the specified name and number of queues. The name parameter can be augmented with %d
to denote a OS determined incrementing ID to assign this device. To get the real device
name call TokioTun::name()
.
Sourcepub fn get<I>(&self, index: I) -> Option<&AsyncStdQueue>
pub fn get<I>(&self, index: I) -> Option<&AsyncStdQueue>
Retrieve an immutable reference to the specified AsyncStdQueue if the suplied SliceIndex is inbounds.
Sourcepub fn get_mut<I>(&mut self, index: I) -> Option<&mut AsyncStdQueue>
pub fn get_mut<I>(&mut self, index: I) -> Option<&mut AsyncStdQueue>
Retrieve a mutable reference to the specified AsyncStdQueue if the suplied SliceIndex is inbounds.
Sourcepub fn close(&mut self) -> Result<()>
pub fn close(&mut self) -> Result<()>
Close the device destroying all internal queues.
NOTE: If drain
is called its on the caller to cleanup the queues.
Sourcepub fn drain<R>(&mut self, range: R) -> Drain<'_, AsyncStdQueue>where
R: RangeBounds<usize>,
pub fn drain<R>(&mut self, range: R) -> Drain<'_, AsyncStdQueue>where
R: RangeBounds<usize>,
Drain the internal queues, passing ownership of the queue and its lifecycle to the caller. This is useful in certain scenarios where extreme control over threading and I/O operations is desired.
Sourcepub fn iter(&self) -> Iter<'_, AsyncStdQueue>
pub fn iter(&self) -> Iter<'_, AsyncStdQueue>
Iterate over immutable instances internal AsyncStdQueue instances.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, AsyncStdQueue>
pub fn iter_mut(&mut self) -> IterMut<'_, AsyncStdQueue>
Iterate over mutable instances of the internal AsyncStdQueue instances.
Sourcepub async fn send(&self, datagram: &[u8]) -> Result<usize>
pub async fn send(&self, datagram: &[u8]) -> Result<usize>
Send a packet asynchronously to an available queue. This method handles collecting
all of the AsyncStdQueue::writable()
futures. Then leverages select_all
to await the first available queue to send the datagram via.
Sourcepub async fn send_via(&self, queue: usize, datagram: &[u8]) -> Result<usize>
pub async fn send_via(&self, queue: usize, datagram: &[u8]) -> Result<usize>
Send a packet asynchronously via the specified TUN queue, see the AsyncStdQueue::send()
documentation for more details.
§Errors
General I/O errors are possible, along with a Error::InvalidQueue if the specified queue is out of range for this device.
Sourcepub async fn recv(&self, datagram: &mut [u8]) -> Result<usize>
pub async fn recv(&self, datagram: &mut [u8]) -> Result<usize>
Receive a packet asynchronously from an available queue. This method handles collecting
all of the AsyncStdQueue::readable()
futures. Then leverages select_all
to await the
first available queue to send the datagram via.
Sourcepub async fn recv_via(&self, queue: usize, datagram: &mut [u8]) -> Result<usize>
pub async fn recv_via(&self, queue: usize, datagram: &mut [u8]) -> Result<usize>
Receive a packet asynchronously from the specified TUN queue, see the AsyncStdQueue::recv()
documentation for more details.
§Errors
General I/O errors are possible, along with a Error::InvalidQueue if the specified queue is out of range for this device.