Session

Struct Session 

Source
pub struct Session { /* private fields */ }
Expand description

Implementations§

Source§

impl Session

Source

pub fn get_adapter(&self) -> Arc<Adapter>

Source

pub fn allocate_send_packet( self: &Arc<Self>, size: u16, ) -> Result<Packet, Error>

Allocates a send packet of the specified size. Wraps WintunAllocateSendPacket

All packets returned from this function must be sent using Session::send_packet because wintun establishes the send packet order based on the invocation order of this function. Therefore if a packet is allocated using this function, and then never sent, it will hold up the send queue for all other packets allocated in the future. It is okay for the session to shutdown with allocated packets that have not yet been sent

Source

pub fn send_packet(&self, packet: Packet)

Sends a packet previously allocated with Session::allocate_send_packet

Source

pub fn try_receive(self: &Arc<Self>) -> Result<Option<Packet>, Error>

Attempts to receive a packet from the virtual interface without blocking. If there are no packets currently in the receive queue, this function returns Ok(None) without blocking. If blocking until a packet is desirable, use Session::receive_blocking

Source

pub fn get_read_wait_event(&self) -> Result<UnsafeHandle<HANDLE>, Error>

§Safety

Returns the low level read event handle that is signaled when more data becomes available to read

Source

pub fn get_shutdown_event(&self) -> UnsafeHandle<HANDLE>

Source

pub fn receive_blocking(self: &Arc<Self>) -> Result<Packet, Error>

Blocks until a packet is available, returning the next packet in the receive queue once this happens. If the session is closed via Session::shutdown all threads currently blocking inside this function will return Err(())

Source

pub fn wait_read(&self) -> Result<(), Error>

Source

pub fn shutdown(&self) -> Result<(), Error>

Cancels any active calls to Session::receive_blocking making them instantly return Err(_) so that session can be shutdown cleanly

Source§

impl Session

Source

pub fn try_recv(&self, buf: &mut [u8]) -> Result<usize>

Source

pub fn recv(&self, buf: &mut [u8]) -> Result<usize>

Blocks until a packet is available, returning the next packet in the receive queue once this happens. If the session is closed via Session::shutdown all threads currently blocking inside this function will return Err(())

Source

pub fn send(&self, buf: &[u8]) -> Result<usize>

Trait Implementations§

Source§

impl Drop for Session

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.