Struct vmm_vhost::unix::PlatformConnection
source · pub struct PlatformConnection {
sock: ScmSocket<UnixStream>,
}
Expand description
Unix domain socket based vhost-user connection.
Fields§
§sock: ScmSocket<UnixStream>
Implementations§
source§impl SocketPlatformConnection
impl SocketPlatformConnection
sourcefn send_iovec_all(
&self,
iovs: &mut [&[u8]],
fds: Option<&[RawDescriptor]>
) -> Result<()>
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.
sourcepub fn send_message(
&self,
hdr: &[u8],
body: &[u8],
payload: &[u8],
fds: Option<&[RawDescriptor]>
) -> Result<()>
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 headerbody
: vhost message body (may be empty to send a header-only message)payload
: additional bytes to append tobody
(may be empty)
sourcepub fn recv_into_bufs(
&self,
bufs: &mut [IoSliceMut<'_>],
allow_fd: bool
) -> Result<(usize, Option<Vec<File>>)>
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:
- file descriptors are attached to a message.
- 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.