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>
impl<H: Hal, T: Transport, const RX_BUFFER_SIZE: usize> VirtIOSocket<H, T, RX_BUFFER_SIZE>
Sourcepub fn connect(&mut self, connection_info: &ConnectionInfo) -> Result
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.
Sourcepub fn accept(&mut self, connection_info: &ConnectionInfo) -> Result
pub fn accept(&mut self, connection_info: &ConnectionInfo) -> Result
Accepts the given connection from a peer.
Sourcepub fn send(
&mut self,
buffer: &[u8],
connection_info: &mut ConnectionInfo,
) -> Result
pub fn send( &mut self, buffer: &[u8], connection_info: &mut ConnectionInfo, ) -> Result
Sends the buffer to the destination.
Sourcepub fn credit_update(&mut self, connection_info: &ConnectionInfo) -> Result
pub fn credit_update(&mut self, connection_info: &ConnectionInfo) -> Result
Tells the peer how much buffer space we have to receive data.
Sourcepub fn poll(
&mut self,
handler: impl FnOnce(VsockEvent, &[u8]) -> Result<Option<VsockEvent>>,
) -> Result<Option<VsockEvent>>
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.
Sourcepub fn shutdown_with_hints(
&mut self,
connection_info: &ConnectionInfo,
hints: StreamShutdown,
) -> Result
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.
Sourcepub fn shutdown(&mut self, connection_info: &ConnectionInfo) -> Result
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.
Sourcepub fn force_close(&mut self, connection_info: &ConnectionInfo) -> Result
pub fn force_close(&mut self, connection_info: &ConnectionInfo) -> Result
Forcibly closes the connection without waiting for the peer.