Skip to main content
Glama
vsock.rs1.25 kB
use std::task::{ Context, Poll, }; use futures::ready; use hyper::server::accept::Accept; use thiserror::Error; use tokio_vsock::{ VsockAddr, VsockListener, VsockStream, }; #[remain::sorted] #[derive(Debug, Error)] pub enum VsockIncomingStreamError { #[error("failed to bind to vsock: {1}")] Bind(#[source] std::io::Error, VsockAddr), #[error("IO error")] IO(#[from] std::io::Error), } type Result<T> = std::result::Result<T, VsockIncomingStreamError>; pub struct VsockIncomingStream { vsock: VsockListener, } // Change this to Port, so that Vsock can pick up the port and translate onto the host v.sock impl VsockIncomingStream { pub async fn create(addr: VsockAddr) -> Result<Self> { let vsock = VsockListener::bind(addr).map_err(|err| VsockIncomingStreamError::Bind(err, addr))?; Ok(Self { vsock }) } } impl Accept for VsockIncomingStream { type Conn = VsockStream; type Error = VsockIncomingStreamError; fn poll_accept( self: std::pin::Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Result<Self::Conn>>> { let (stream, _addr) = ready!(self.vsock.poll_accept(cx))?; Poll::Ready(Some(Ok(stream))) } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/systeminit/si'

If you have feedback or need assistance with the MCP directory API, please join our Discord server