VsockSocket

Struct VsockSocket 

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

A virtio sequential packet socket between a local and a remote host.

This is the vsock equivalent of std::net::UdpSocket.

Implementations§

Source§

impl VsockSocket

Source

pub fn bind<A: SockaddrLike>(addr: &A) -> Result<Self>

Bind to an address and listen for connections.

Analogous to std::net::UdpSocket::bind

Source

pub fn bind_with_cid_port(cid: u32, port: u32) -> Result<Self>

Bind to a specified cid and port and listen for connections.

Source

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

Receive a message from a remote host.

Analogous to std::net::UdpSocket::recv_from

§Returns

The number of bytes read and the address of the remote host.

Source

pub fn send_to<A: SockaddrLike>(&self, buf: &[u8], addr: &A) -> Result<usize>

Send a message to a remote host.

Analogous to std::net::UdpSocket::send_to

Source

pub fn send_to_with_cid_port( &self, buf: &[u8], cid: u32, port: u32, ) -> Result<usize>

Send a message to a remote host with specified cid and port.

Source

pub fn peer_addr(&self) -> Result<VsockAddr>

Virtio socket address of the remote peer associated with this connection.

Source

pub fn local_addr(&self) -> Result<VsockAddr>

Virtio socket address of the local address associated with this connection.

Source

pub fn try_clone(&self) -> Result<Self>

Create a new independently owned handle to the underlying socket.

Source

pub fn set_read_timeout(&self, dur: Option<Duration>) -> Result<()>

Set the timeout on read operations.

Source

pub fn set_write_timeout(&self, dur: Option<Duration>) -> Result<()>

Set the timeout on write operations.

Source

pub fn take_error(&self) -> Result<Option<Error>>

Retrieve the latest error associated with the underlying socket.

Source

pub fn connect<A: SockaddrLike>(&self, addr: &A) -> Result<()>

Open a connection to a remote host (you need to bind to an address with Self::bind first).

Allows you to send and receive messages from this host directly through Self::send and Self::recv.

Analogous to std::net::UdpSocket::connect

Source

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

Open a connection to a remote host with specified cid and port (you need to bind to an address with Self::bind first).

Allows you to send and receive messages from this host directly through Self::send and Self::recv.

Source

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

Send data to the connected remote host.

Analogous to std::net::UdpSocket::send

Source

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

Receive data from the connected remote host.

Analogous to std::net::UdpSocket::recv

Source

pub fn set_nonblocking(&self, nonblocking: bool) -> Result<()>

Move this stream in and out of nonblocking mode.

Trait Implementations§

Source§

impl AsFd for VsockSocket

Source§

fn as_fd(&self) -> BorrowedFd<'_>

Borrows the file descriptor. Read more
Source§

impl AsRawFd for VsockSocket

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl Debug for VsockSocket

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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 IntoRawFd for VsockSocket

Source§

fn into_raw_fd(self) -> RawFd

Consumes this object, returning the raw underlying file descriptor. Read more

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.