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
impl VsockSocket
Sourcepub fn bind<A: SockaddrLike>(addr: &A) -> Result<Self>
pub fn bind<A: SockaddrLike>(addr: &A) -> Result<Self>
Bind to an address and listen for connections.
Analogous to std::net::UdpSocket::bind
Sourcepub fn bind_with_cid_port(cid: u32, port: u32) -> Result<Self>
pub fn bind_with_cid_port(cid: u32, port: u32) -> Result<Self>
Bind to a specified cid and port and listen for connections.
Sourcepub fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, VsockAddr)>
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.
Sourcepub fn send_to<A: SockaddrLike>(&self, buf: &[u8], addr: &A) -> Result<usize>
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
Sourcepub fn send_to_with_cid_port(
&self,
buf: &[u8],
cid: u32,
port: u32,
) -> Result<usize>
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.
Sourcepub fn peer_addr(&self) -> Result<VsockAddr>
pub fn peer_addr(&self) -> Result<VsockAddr>
Virtio socket address of the remote peer associated with this connection.
Sourcepub fn local_addr(&self) -> Result<VsockAddr>
pub fn local_addr(&self) -> Result<VsockAddr>
Virtio socket address of the local address associated with this connection.
Sourcepub fn try_clone(&self) -> Result<Self>
pub fn try_clone(&self) -> Result<Self>
Create a new independently owned handle to the underlying socket.
Sourcepub fn set_read_timeout(&self, dur: Option<Duration>) -> Result<()>
pub fn set_read_timeout(&self, dur: Option<Duration>) -> Result<()>
Set the timeout on read operations.
Sourcepub fn set_write_timeout(&self, dur: Option<Duration>) -> Result<()>
pub fn set_write_timeout(&self, dur: Option<Duration>) -> Result<()>
Set the timeout on write operations.
Sourcepub fn take_error(&self) -> Result<Option<Error>>
pub fn take_error(&self) -> Result<Option<Error>>
Retrieve the latest error associated with the underlying socket.
Sourcepub fn connect<A: SockaddrLike>(&self, addr: &A) -> Result<()>
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
Sourcepub fn connect_with_cid_port(&self, cid: u32, port: u32) -> Result<()>
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.
Sourcepub fn send(&self, buf: &[u8]) -> Result<usize>
pub fn send(&self, buf: &[u8]) -> Result<usize>
Send data to the connected remote host.
Analogous to std::net::UdpSocket::send
Sourcepub fn recv(&self, buf: &mut [u8]) -> Result<usize>
pub fn recv(&self, buf: &mut [u8]) -> Result<usize>
Receive data from the connected remote host.
Analogous to std::net::UdpSocket::recv
Sourcepub fn set_nonblocking(&self, nonblocking: bool) -> Result<()>
pub fn set_nonblocking(&self, nonblocking: bool) -> Result<()>
Move this stream in and out of nonblocking mode.
Trait Implementations§
Source§impl AsFd for VsockSocket
impl AsFd for VsockSocket
Source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
Source§impl AsRawFd for VsockSocket
impl AsRawFd for VsockSocket
Source§impl Debug for VsockSocket
impl Debug for VsockSocket
Source§impl FromRawFd for VsockSocket
impl FromRawFd for VsockSocket
Source§unsafe fn from_raw_fd(fd: RawFd) -> Self
unsafe fn from_raw_fd(fd: RawFd) -> Self
Self from the given raw file
descriptor. Read more