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. --- jsonrpc/src/server.rs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'jsonrpc/src/server.rs') diff --git a/jsonrpc/src/server.rs b/jsonrpc/src/server.rs index 05ef7da..0038e89 100644 --- a/jsonrpc/src/server.rs +++ b/jsonrpc/src/server.rs @@ -7,13 +7,14 @@ use karyons_core::{ async_util::{TaskGroup, TaskResult}, Executor, }; -use karyons_net::{listen, Conn, Endpoint, Listener}; + +use karyons_net::{Conn, Listener}; use crate::{ codec::{Codec, CodecConfig}, message, service::RPCService, - Error, Result, JSONRPC_VERSION, + Endpoint, Error, Result, JSONRPC_VERSION, }; /// RPC server config @@ -31,7 +32,7 @@ pub struct Server<'a> { } impl<'a> Server<'a> { - /// Creates a new RPC server. + /// Creates a new RPC server by passing a listener. It supports Tcp, Unix, and Tls. pub fn new(listener: Box, config: ServerConfig, ex: Executor<'a>) -> Arc { Arc::new(Self { listener, @@ -41,19 +42,9 @@ impl<'a> Server<'a> { }) } - /// Creates a new RPC server using the provided endpoint. - pub async fn new_with_endpoint( - endpoint: &Endpoint, - config: ServerConfig, - ex: Executor<'a>, - ) -> Result> { - let listener = listen(endpoint).await?; - Ok(Arc::new(Self { - listener, - services: RwLock::new(HashMap::new()), - task_group: TaskGroup::new(ex), - config, - })) + /// Returns the local endpoint. + pub fn local_endpoint(&self) -> Result { + self.listener.local_endpoint().map_err(Error::KaryonsNet) } /// Starts the RPC server -- cgit v1.2.3