pub struct VirtIOSocket<H: Hal, T: Transport> { /* private fields */ }
Expand description

Low-level driver for a VirtIO socket device.

You probably want to use VsockConnectionManager rather than using this directly.

Implementations§

source§

impl<H: Hal, T: Transport> VirtIOSocket<H, T>

source

pub fn new(transport: T) -> Result<Self>

Create a new VirtIO Vsock driver.

source

pub fn guest_cid(&self) -> u64

Returns the CID which has been assigned to this guest.

source

pub fn connect(&mut self, connection_info: &ConnectionInfo) -> Result

Sends a request to connect to the given destination.

This returns as soon as the request is sent; you should wait until poll returns a VsockEventType::Connected event indicating that the peer has accepted the connection before sending data.

source

pub fn accept(&mut self, connection_info: &ConnectionInfo) -> Result

Accepts the given connection from a peer.

source

pub fn send( &mut self, buffer: &[u8], connection_info: &mut ConnectionInfo ) -> Result

Sends the buffer to the destination.

source

pub fn credit_update(&mut self, connection_info: &ConnectionInfo) -> Result

Tells the peer how much buffer space we have to receive data.

source

pub fn poll( &mut self, handler: impl FnOnce(VsockEvent, &[u8]) -> Result<Option<VsockEvent>> ) -> Result<Option<VsockEvent>>

Polls the RX virtqueue for the next event, and calls the given handler function to handle it.

source

pub fn shutdown(&mut self, connection_info: &ConnectionInfo) -> Result

Requests to shut down the connection cleanly.

This returns as soon as the request is sent; you should wait until poll returns a VsockEventType::Disconnected event if you want to know that the peer has acknowledged the shutdown.

source

pub fn force_close(&mut self, connection_info: &ConnectionInfo) -> Result

Forcibly closes the connection without waiting for the peer.

Trait Implementations§

source§

impl<H: Hal, T: Transport> Drop for VirtIOSocket<H, T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<H, T> RefUnwindSafe for VirtIOSocket<H, T>where H: RefUnwindSafe, T: RefUnwindSafe,

§

impl<H, T> !Send for VirtIOSocket<H, T>

§

impl<H, T> !Sync for VirtIOSocket<H, T>

§

impl<H, T> Unpin for VirtIOSocket<H, T>where H: Unpin, T: Unpin,

§

impl<H, T> UnwindSafe for VirtIOSocket<H, T>where H: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

fn into(self) -> U

Calls U::from(self).

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

source§

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

§

type Error = Infallible

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

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

Performs the conversion.
source§

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

§

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

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

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

Performs the conversion.