pub enum VsockPortOrId {
Port(u32),
Id(Guid),
}Expand description
Represents the local or remote port number for a vsock connection, or the service ID or instance ID for an hvsocket connection.
Variants§
Port(u32)
The vsock port number.
Id(Guid)
The hvsocket service ID or instance ID, represented as a GUID.
Implementations§
Source§impl VsockPortOrId
impl VsockPortOrId
Sourcepub fn port(&self) -> Option<u32>
pub fn port(&self) -> Option<u32>
Gets the vsock port number. This will return Some if the instance either directly uses a
port, or uses a service ID that matches the hvsocket vsock template.
Sourcepub fn id(&self) -> Guid
pub fn id(&self) -> Guid
Gets the vsock service ID. If this instance is a port, it will use the hvsocket vsock template to construct a service ID.
Sourcepub fn port_to_id(port: u32) -> Guid
pub fn port_to_id(port: u32) -> Guid
Converts a vsock port number into a GUID using the hvsocket vsock template.
Sourcepub fn host_uds_path(
&self,
base_path: impl AsRef<Path>,
) -> Result<PathBuf, UdsPathError>
pub fn host_uds_path( &self, base_path: impl AsRef<Path>, ) -> Result<PathBuf, UdsPathError>
Gets the path of a Unix domain socket listener on the host using this port or id.
If this instance is a port, or uses a GUID that matches the hvsocket vsock template, this function will first use a path with that port number appended. If that path doesn’t exist, or if this instance uses a non-vsock GUID, it will use a path with the full ID.
Sourcepub fn parse_connect_request(buf: &[u8]) -> Result<Self, ParseError>
pub fn parse_connect_request(buf: &[u8]) -> Result<Self, ParseError>
Parses a connection request from a buffer containing a UTF-8 string of the format “CONNECT <port or service ID>\n”.
Sourcepub fn get_ok_response(&self) -> String
pub fn get_ok_response(&self) -> String
Gets the response string that should be sent back to the guest on a successful connection, of the format “OK <port or service ID>\n”.
In this case, any instance using a GUID will be formatted using the full service ID, even if it matches the hvsocket vsock template. The format returned should always match the format that was used in the “CONNECT” request.
Sourcepub fn write_ok_response(&self, buf: &mut [u8]) -> usize
pub fn write_ok_response(&self, buf: &mut [u8]) -> usize
Writes the response string that should be sent back to the guest on a successful connection into the provided buffer, and returns the number of bytes written.
§Panics
This function will panic if the buffer is too small to hold the response.
Trait Implementations§
Source§impl Clone for VsockPortOrId
impl Clone for VsockPortOrId
Source§fn clone(&self) -> VsockPortOrId
fn clone(&self) -> VsockPortOrId
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more