virtio_drivers::device::socket

Struct VirtIOSocket

Source
pub struct VirtIOSocket<H: Hal, T: Transport, const RX_BUFFER_SIZE: usize = DEFAULT_RX_BUFFER_SIZE> { /* private fields */ }
Expand description

Low-level driver for a VirtIO socket device.

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

RX_BUFFER_SIZE is the size in bytes of each buffer used in the RX virtqueue. This must be bigger than size_of::<VirtioVsockHdr>().

Implementations§

Source§

impl<H: Hal, T: Transport, const RX_BUFFER_SIZE: usize> VirtIOSocket<H, T, RX_BUFFER_SIZE>

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_with_hints( &mut self, connection_info: &ConnectionInfo, hints: StreamShutdown, ) -> Result

Requests to shut down the connection cleanly, sending hints about whether we will send or receive more data.

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 shutdown(&mut self, connection_info: &ConnectionInfo) -> Result

Requests to shut down the connection cleanly, telling the peer that we won’t send or receive any more data.

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, const RX_BUFFER_SIZE: usize> Drop for VirtIOSocket<H, T, RX_BUFFER_SIZE>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<H, T, const RX_BUFFER_SIZE: usize> Freeze for VirtIOSocket<H, T, RX_BUFFER_SIZE>
where T: Freeze,

§

impl<H, T, const RX_BUFFER_SIZE: usize> RefUnwindSafe for VirtIOSocket<H, T, RX_BUFFER_SIZE>
where T: RefUnwindSafe, H: RefUnwindSafe,

§

impl<H, T, const RX_BUFFER_SIZE: usize> Send for VirtIOSocket<H, T, RX_BUFFER_SIZE>
where T: Send,

§

impl<H, T, const RX_BUFFER_SIZE: usize> Sync for VirtIOSocket<H, T, RX_BUFFER_SIZE>
where T: Sync,

§

impl<H, T, const RX_BUFFER_SIZE: usize> Unpin for VirtIOSocket<H, T, RX_BUFFER_SIZE>
where T: Unpin, H: Unpin,

§

impl<H, T, const RX_BUFFER_SIZE: usize> UnwindSafe for VirtIOSocket<H, T, RX_BUFFER_SIZE>
where T: UnwindSafe, H: UnwindSafe,

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.