From 7d6c0e68a19ad5e2e4e05cfc219d446be6ff2286 Mon Sep 17 00:00:00 2001 From: hozan23 Date: Thu, 30 Nov 2023 22:52:53 +0300 Subject: jsonrpc: Enhance the API and add support for TCP, Unix, and TLS protocols. --- net/src/transports/tcp.rs | 12 ++++++++++++ net/src/transports/tls.rs | 12 ++++++++++++ net/src/transports/udp.rs | 6 ++++++ net/src/transports/unix.rs | 12 ++++++++++++ 4 files changed, 42 insertions(+) (limited to 'net/src') diff --git a/net/src/transports/tcp.rs b/net/src/transports/tcp.rs index 37f00a7..37ad860 100644 --- a/net/src/transports/tcp.rs +++ b/net/src/transports/tcp.rs @@ -83,3 +83,15 @@ pub async fn listen_tcp(addr: &Addr, port: &Port) -> Result { let listener = TcpListener::bind(address).await?; Ok(listener) } + +impl From for Box { + fn from(conn: TcpStream) -> Self { + Box::new(TcpConn::new(conn)) + } +} + +impl From for Box { + fn from(listener: TcpListener) -> Self { + Box::new(listener) + } +} diff --git a/net/src/transports/tls.rs b/net/src/transports/tls.rs index 01bb5aa..cbb3d99 100644 --- a/net/src/transports/tls.rs +++ b/net/src/transports/tls.rs @@ -138,3 +138,15 @@ pub async fn listen( .await .map(|l| Box::new(l) as Box) } + +impl From> for Box { + fn from(conn: TlsStream) -> Self { + Box::new(TlsConn::new(conn.get_ref().0.clone(), conn)) + } +} + +impl From for Box { + fn from(listener: TlsListener) -> Self { + Box::new(listener) + } +} diff --git a/net/src/transports/udp.rs b/net/src/transports/udp.rs index 8a2fbec..9576876 100644 --- a/net/src/transports/udp.rs +++ b/net/src/transports/udp.rs @@ -73,3 +73,9 @@ pub async fn listen_udp(addr: &Addr, port: &Port) -> Result { let udp_conn = UdpConn::new(conn); Ok(udp_conn) } + +impl From for Box { + fn from(conn: UdpSocket) -> Self { + Box::new(UdpConn::new(conn)) + } +} diff --git a/net/src/transports/unix.rs b/net/src/transports/unix.rs index e504934..0698975 100644 --- a/net/src/transports/unix.rs +++ b/net/src/transports/unix.rs @@ -74,3 +74,15 @@ pub fn listen_unix(path: &String) -> Result { let listener = UnixListener::bind(path)?; Ok(listener) } + +impl From for Box { + fn from(conn: UnixStream) -> Self { + Box::new(UnixConn::new(conn)) + } +} + +impl From for Box { + fn from(listener: UnixListener) -> Self { + Box::new(listener) + } +} -- cgit v1.2.3