aboutsummaryrefslogtreecommitdiff
path: root/karyons_net/src/listener.rs
diff options
context:
space:
mode:
authorhozan23 <hozan23@proton.me>2023-11-09 11:38:19 +0300
committerhozan23 <hozan23@proton.me>2023-11-09 11:38:19 +0300
commit849d827486c75b2ab223d7b0e638dbb5b74d4d1d (patch)
tree41cd3babc37147ec4a40cab8ce8ae31c91cce33b /karyons_net/src/listener.rs
parentde1354525895ffbad18f90a5246fd65157f7449e (diff)
rename crates
Diffstat (limited to 'karyons_net/src/listener.rs')
-rw-r--r--karyons_net/src/listener.rs39
1 files changed, 0 insertions, 39 deletions
diff --git a/karyons_net/src/listener.rs b/karyons_net/src/listener.rs
deleted file mode 100644
index 31a63ae..0000000
--- a/karyons_net/src/listener.rs
+++ /dev/null
@@ -1,39 +0,0 @@
-use crate::{Endpoint, Error, Result};
-use async_trait::async_trait;
-
-use crate::{
- transports::{tcp, unix},
- Conn,
-};
-
-/// Listener is a generic network listener.
-#[async_trait]
-pub trait Listener: Send + Sync {
- fn local_endpoint(&self) -> Result<Endpoint>;
- async fn accept(&self) -> Result<Conn>;
-}
-
-/// Listens to the provided endpoint.
-///
-/// it only supports `tcp4/6` and `unix`.
-///
-/// #Example
-///
-/// ```
-/// use karyons_net::{Endpoint, listen};
-///
-/// async {
-/// let endpoint: Endpoint = "tcp://127.0.0.1:3000".parse().unwrap();
-///
-/// let listener = listen(&endpoint).await.unwrap();
-/// let conn = listener.accept().await.unwrap();
-/// };
-///
-/// ```
-pub async fn listen(endpoint: &Endpoint) -> Result<Box<dyn Listener>> {
- match endpoint {
- Endpoint::Tcp(addr, port) => Ok(Box::new(tcp::listen_tcp(addr, port).await?)),
- Endpoint::Unix(addr) => Ok(Box::new(unix::listen_unix(addr)?)),
- _ => Err(Error::InvalidEndpoint(endpoint.to_string())),
- }
-}