use arcbox_transport::Transport;
use arcbox_transport::vsock::{BlockingVsockTransport, VsockTransport};
use bytes::Bytes;
use std::time::Duration;
pub(super) enum AgentTransport {
Async(VsockTransport),
Blocking(BlockingVsockTransport),
}
pub(super) const BLOCKING_RPC_TIMEOUT: Duration = Duration::from_secs(5);
impl AgentTransport {
pub(super) async fn async_send(
&mut self,
data: Bytes,
) -> std::result::Result<(), arcbox_transport::error::TransportError> {
match self {
Self::Async(t) => t.send(data).await,
Self::Blocking(_) => Err(arcbox_transport::error::TransportError::Protocol(
"streaming RPCs not supported on blocking transport".into(),
)),
}
}
pub(super) async fn async_recv(
&mut self,
) -> std::result::Result<Bytes, arcbox_transport::error::TransportError> {
match self {
Self::Async(t) => t.recv().await,
Self::Blocking(_) => Err(arcbox_transport::error::TransportError::Protocol(
"streaming RPCs not supported on blocking transport".into(),
)),
}
}
pub(super) fn into_split(
self,
) -> std::result::Result<
(
arcbox_transport::vsock::VsockSender,
arcbox_transport::vsock::VsockReceiver,
),
arcbox_transport::error::TransportError,
> {
match self {
Self::Async(t) => t.into_split(),
Self::Blocking(_) => Err(arcbox_transport::error::TransportError::Protocol(
"split not supported on blocking transport".into(),
)),
}
}
}