firecracker_sdk/vm/vm_socket/mod.rs
1use std::path::Path;
2
3use anyhow::Result;
4use tokio::net::UnixSocket;
5
6use crate::vm::VM;
7
8/// Structure for initializing a Unix socket for communication with a VM
9pub struct VMSocket {
10 socket: UnixSocket,
11}
12
13impl VMSocket {
14 pub fn new() -> Result<Self> {
15 Ok(Self {
16 socket: UnixSocket::new_stream()?,
17 })
18 }
19
20 /// Creates a Unix stream for communicating with the VM via a specified path
21 pub async fn connect<P: AsRef<Path>>(self, path: P) -> Result<VM> {
22 let stream = self.socket.connect(&path).await?;
23 Ok(VM::new(stream))
24 }
25}