pub struct Connection<R: Req>(pub(crate) PlatformConnection, PhantomData<R>, PhantomData<Cell<()>>);
Expand description

A vhost-user connection at a low abstraction level. Provides methods for sending and receiving vhost-user message headers and bodies.

Builds on top of PlatformConnection, which provides methods for sending and receiving raw bytes and file descriptors (a thin cross-platform abstraction for unix domain sockets).

Tuple Fields§

§0: PlatformConnection§1: PhantomData<R>§2: PhantomData<Cell<()>>

Implementations§

source§

impl<R: Req> Connection<R>

source

pub fn connect<P: AsRef<Path>>(path: P) -> Result<Self>

Create a new stream by connecting to server at path.

source

pub fn send_header_only_message( &self, hdr: &VhostUserMsgHeader<R>, fds: Option<&[RawDescriptor]> ) -> Result<()>

Sends a header-only message with optional attached file descriptors.

source

pub fn send_message<T: AsBytes>( &self, hdr: &VhostUserMsgHeader<R>, body: &T, fds: Option<&[RawDescriptor]> ) -> Result<()>

Send a message with header and body. Optional file descriptors may be attached to the message.

source

pub fn send_message_with_payload<T: Sized + AsBytes>( &self, hdr: &VhostUserMsgHeader<R>, body: &T, payload: &[u8], fds: Option<&[RawDescriptor]> ) -> Result<()>

Send a message with header and body. payload is appended to the end of the body. Optional file descriptors may also be attached to the message.

source

fn recv_into_bufs_all(&self, bufs: &mut [&mut [u8]]) -> Result<Vec<File>>

Reads all bytes into the given scatter/gather vectors with optional attached files. Will loop until all data has been transfered and errors if EOF is reached before then.

Return:
    • received fds on success
    • Disconnect - client is closed
TODO

This function takes a slice of &mut [u8] instead of IoSliceMut because the internal cursor needs to be moved by advance_slices_mut(). Once IoSliceMut::advance_slices() becomes stable, this should be updated. https://github.com/rust-lang/rust/issues/62726.

source

pub fn recv_header(&self) -> Result<(VhostUserMsgHeader<R>, Vec<File>)>

Receive message header

Errors if the header is invalid.

Note, only the first MAX_ATTACHED_FD_ENTRIES file descriptors will be accepted and all other file descriptor will be discard silently.

source

pub fn recv_body_bytes(&self, hdr: &VhostUserMsgHeader<R>) -> Result<Vec<u8>>

Receive the body following the header hdr.

source

pub fn recv_message<T: AsBytes + FromBytes + VhostUserMsgValidator>( &self ) -> Result<(VhostUserMsgHeader<R>, T, Vec<File>)>

Receive a message header and body.

Errors if the header or body is invalid.

Note, only the first MAX_ATTACHED_FD_ENTRIES file descriptors will be accepted and all other file descriptor will be discard silently.

source

pub fn recv_message_with_payload<T: AsBytes + FromBytes + VhostUserMsgValidator>( &self ) -> Result<(VhostUserMsgHeader<R>, T, Vec<u8>, Vec<File>)>

Receive a message header and body, where the body includes a variable length payload at the end.

Errors if the header or body is invalid.

Note, only the first MAX_ATTACHED_FD_ENTRIES file descriptors will be accepted and all other file descriptor will be discard silently.

Trait Implementations§

source§

impl<R: Req> AsRawDescriptor for Connection<R>

source§

fn as_raw_descriptor(&self) -> RawDescriptor

Returns the underlying raw descriptor. Read more
source§

impl<R: Req> From<UnixStream> for Connection<R>

source§

fn from(sock: SystemStream) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<R> !RefUnwindSafe for Connection<R>

§

impl<R> Send for Connection<R>

§

impl<R> !Sync for Connection<R>

§

impl<R> Unpin for Connection<R>where R: Unpin,

§

impl<R> UnwindSafe for Connection<R>where R: 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
§

impl<T> AsRawDescriptors for Twhere T: AsRawDescriptor,

§

fn as_raw_descriptors(&self) -> Vec<i32, Global>

Returns the underlying raw descriptors. 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.