Skip to main content

VsockStreamBackend

Trait VsockStreamBackend 

Source
pub trait VsockStreamBackend: Send {
    // Required methods
    fn read(&self, buf: &mut [u8]) -> Result<usize, Error>;
    fn write(&self, buf: &[u8]) -> Result<usize, Error>;
    fn shutdown(&self, how: VsockShutdown) -> Result<(), Error>;

    // Provided methods
    fn connect_state(&self) -> Result<VsockConnectState, Error> { ... }
    fn pollable(&self) -> Option<i32> { ... }
}
Expand description

One nonblocking byte stream served by a custom vsock backend.

Implementations return io::ErrorKind::WouldBlock when progress is not currently possible. The VsockNotifier supplied at connection time must be signaled whenever a blocked operation may make progress; libkrun continues to own virtio-vsock framing, credit flow, shutdown, and reset handling around this stream.

Required Methods§

Source

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

Read bytes that should be delivered to the guest.

Source

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

Consume bytes received from the guest.

Source

fn shutdown(&self, how: VsockShutdown) -> Result<(), Error>

Apply a guest-requested half-close or full shutdown.

Provided Methods§

Source

fn connect_state(&self) -> Result<VsockConnectState, Error>

Report whether a nonblocking host connection has completed.

In-process backends are ready immediately. Socket-backed implementations can return VsockConnectState::Connecting until their poll fd becomes writable and then surface the result of SO_ERROR here.

Source

fn pollable(&self) -> Option<i32>

Return a pollable host object when the backend has one.

Returning None keeps the existing notifier-driven behavior. Returning a native object lets libkrun poll a real socket or handle directly.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§