pub struct PlatformConnection {
    sock: ScmSocket<UnixStream>,
}
Expand description

Unix domain socket based vhost-user connection.

Fields§

§sock: ScmSocket<UnixStream>

Implementations§

source§

impl SocketPlatformConnection

source

fn send_iovec_all( &self, iovs: &mut [&[u8]], fds: Option<&[RawDescriptor]> ) -> Result<()>

Sends all bytes from scatter-gather vectors with optional attached file descriptors. Will loop until all data has been transfered.

§TODO

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

source

pub fn send_message( &self, hdr: &[u8], body: &[u8], payload: &[u8], fds: Option<&[RawDescriptor]> ) -> Result<()>

Sends a single message over the socket with optional attached file descriptors.

  • hdr: vhost message header
  • body: vhost message body (may be empty to send a header-only message)
  • payload: additional bytes to append to body (may be empty)
source

pub fn recv_into_bufs( &self, bufs: &mut [IoSliceMut<'_>], allow_fd: bool ) -> Result<(usize, Option<Vec<File>>)>

Reads bytes from the socket into the given scatter/gather vectors with optional attached file.

The underlying communication channel is a Unix domain socket in STREAM mode. It’s a little tricky to pass file descriptors through such a communication channel. Let’s assume that a sender sending a message with some file descriptors attached. To successfully receive those attached file descriptors, the receiver must obey following rules:

  1. file descriptors are attached to a message.
  2. message(packet) boundaries must be respected on the receive side.

In other words, recvmsg() operations must not cross the packet boundary, otherwise the attached file descriptors will get lost. Note that this function wraps received file descriptors as File.

§Return:
    • (number of bytes received, [received files]) on success
    • Disconnect: the connection is closed.
    • SocketRetry: temporary error caused by signals or short of resources.
    • SocketBroken: the underline socket is broken.
    • SocketError: other socket related errors.

Trait Implementations§

source§

impl AsRawDescriptor for SocketPlatformConnection

source§

fn as_raw_descriptor(&self) -> RawDescriptor

Returns the underlying raw descriptor. Read more
source§

impl ReadNotifier for SocketPlatformConnection

source§

fn get_read_notifier(&self) -> &dyn AsRawDescriptor

Gets a descriptor that can be used in EventContext to wait for events to be available (e.g. to avoid receive_events blocking).

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AsRawDescriptors for T
where T: AsRawDescriptor,

§

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

Returns the underlying raw descriptors. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where 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 T
where 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.