aboutsummaryrefslogtreecommitdiff
path: root/karyons_net/src/connection.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/connection.rs
parentde1354525895ffbad18f90a5246fd65157f7449e (diff)
rename crates
Diffstat (limited to 'karyons_net/src/connection.rs')
-rw-r--r--karyons_net/src/connection.rs57
1 files changed, 0 insertions, 57 deletions
diff --git a/karyons_net/src/connection.rs b/karyons_net/src/connection.rs
deleted file mode 100644
index 518ccfd..0000000
--- a/karyons_net/src/connection.rs
+++ /dev/null
@@ -1,57 +0,0 @@
-use crate::{Endpoint, Result};
-use async_trait::async_trait;
-
-use crate::transports::{tcp, udp, unix};
-
-/// Alias for `Box<dyn Connection>`
-pub type Conn = Box<dyn Connection>;
-
-/// Connection is a generic network connection interface for
-/// `UdpConn`, `TcpConn`, and `UnixConn`.
-///
-/// If you are familiar with the Go language, this is similar to the `Conn`
-/// interface <https://pkg.go.dev/net#Conn>
-#[async_trait]
-pub trait Connection: Send + Sync {
- /// Returns the remote peer endpoint of this connection
- fn peer_endpoint(&self) -> Result<Endpoint>;
-
- /// Returns the local socket endpoint of this connection
- fn local_endpoint(&self) -> Result<Endpoint>;
-
- /// Reads data from this connection.
- async fn recv(&self, buf: &mut [u8]) -> Result<usize>;
-
- /// Sends data to this connection
- async fn send(&self, buf: &[u8]) -> Result<usize>;
-}
-
-/// Connects to the provided endpoint.
-///
-/// it only supports `tcp4/6`, `udp4/6` and `unix`.
-///
-/// #Example
-///
-/// ```
-/// use karyons_net::{Endpoint, dial};
-///
-/// async {
-/// let endpoint: Endpoint = "tcp://127.0.0.1:3000".parse().unwrap();
-///
-/// let conn = dial(&endpoint).await.unwrap();
-///
-/// conn.send(b"MSG").await.unwrap();
-///
-/// let mut buffer = [0;32];
-/// conn.recv(&mut buffer).await.unwrap();
-/// };
-///
-/// ```
-///
-pub async fn dial(endpoint: &Endpoint) -> Result<Conn> {
- match endpoint {
- Endpoint::Tcp(addr, port) => Ok(Box::new(tcp::dial_tcp(addr, port).await?)),
- Endpoint::Udp(addr, port) => Ok(Box::new(udp::dial_udp(addr, port).await?)),
- Endpoint::Unix(addr) => Ok(Box::new(unix::dial_unix(addr).await?)),
- }
-}