Skip to main content

VsockSocket

Struct VsockSocket 

Source
pub struct VsockSocket { /* private fields */ }
Expand description

A vsock SOCK_STREAM socket. Owns its fd; closes on Drop. This is the explicit-CID primitive; for the loopback path use the cross-platform HostVmSocket.

Implementations§

Source§

impl VsockSocket

Source

pub fn new() -> Result<Self>

Create a fresh vsock SOCK_STREAM socket (not yet bound / connected).

Source

pub fn bind(&self, cid: u32, port: u32) -> Result<()>

Bind to (cid, port). Use VMADDR_CID_ANY to bind to any CID.

Source

pub fn listen(&self, backlog: i32) -> Result<()>

Listen on a bound socket.

Source

pub fn accept(&self) -> Result<VsockSocket>

Accept one incoming vsock connection. Returns the connected socket; the listener stays alive.

Source

pub fn connect(&self, cid: u32, port: u32) -> Result<()>

Connect this socket to (cid, port).

Source

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

Blocking send. Returns bytes written.

Source

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

Blocking recv. Returns bytes read.

Trait Implementations§

Source§

impl AsRawFd for VsockSocket

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl Drop for VsockSocket

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl FromRawFd for VsockSocket

Source§

unsafe fn from_raw_fd(fd: RawFd) -> Self

Constructs a new instance of Self from the given raw file descriptor. Read more
Source§

impl Send for VsockSocket

Source§

impl Sync for VsockSocket

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
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>,

Source§

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>,

Source§

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.