From beab67b2e38808f91ecd390190d527fc7db5499d Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 23 Feb 2025 12:14:27 +0100 Subject: call receive tool --- sip/src/transport/mod.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'sip/src/transport/mod.rs') diff --git a/sip/src/transport/mod.rs b/sip/src/transport/mod.rs index b4c512b..b9cdaeb 100644 --- a/sip/src/transport/mod.rs +++ b/sip/src/transport/mod.rs @@ -1,5 +1,7 @@ use crate::encoding::Message; use anyhow::Result; +use tcp::TcpTransport; +use udp::UdpTransport; pub mod tcp; pub mod udp; @@ -9,3 +11,22 @@ pub trait Transport { async fn recv(&self) -> Result; async fn send(&self, message: Message) -> Result<()>; } + +pub enum InetTransport { + Udp(UdpTransport), + Tcp(TcpTransport), +} +impl Transport for InetTransport { + async fn recv(&self) -> Result { + match self { + InetTransport::Udp(t) => t.recv().await, + InetTransport::Tcp(t) => t.recv().await, + } + } + async fn send(&self, message: Message) -> Result<()> { + match self { + InetTransport::Udp(t) => t.send(message).await, + InetTransport::Tcp(t) => t.send(message).await, + } + } +} -- cgit v1.2.3-70-g09d2