firecracker_sdk/firecracker/firecracker_socket/
mod.rs

1use std::path::Path;
2
3use anyhow::Result;
4use tokio::net::UnixSocket;
5
6use crate::firecracker::FirecrackerStream;
7
8/// Structure for initializing a Unix socket for communication with a Firecracker
9pub struct FirecrackerSocket {
10    socket: UnixSocket,
11}
12
13impl FirecrackerSocket {
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 Firecracker via a specified path
21    pub async fn connect<P: AsRef<Path>>(self, path: P) -> Result<FirecrackerStream> {
22        let stream = self.socket.connect(&path).await?;
23        Ok(FirecrackerStream::new(stream))
24    }
25}