diff --git a/examples/outbound.rs b/examples/outbound.rs index 2a67f65..427f121 100644 --- a/examples/outbound.rs +++ b/examples/outbound.rs @@ -29,10 +29,10 @@ async fn main() -> Result<(), EslError> { let addr = "0.0.0.0:8085"; // Listening address println!("Listening on {}", addr); let listener = TcpListener::bind(addr).await?; - let listener = Esl::outbound(listener).await?; loop { let (socket, _) = listener.accept().await?; + let socket = Esl::outbound(socket).await?; tokio::spawn(async move { process_call(socket).await }); } } diff --git a/src/esl.rs b/src/esl.rs index 1032ab2..66cc065 100644 --- a/src/esl.rs +++ b/src/esl.rs @@ -1,6 +1,6 @@ -use tokio::net::{TcpListener, ToSocketAddrs}; +use tokio::net::{TcpStream, ToSocketAddrs}; -use crate::{connection::EslConnection, outbound::Outbound, EslError}; +use crate::{connection::EslConnection, EslError}; #[derive(Debug, Clone, PartialEq, Eq)] pub(crate) enum EslConnectionType { Inbound, @@ -18,7 +18,9 @@ impl Esl { } /// Creates new server for outbound connection - pub async fn outbound(listener: TcpListener) -> Result { - Outbound::new(listener).await + pub async fn outbound(stream: TcpStream) -> Result { + let connection = + EslConnection::with_tcpstream(stream, "None", EslConnectionType::Outbound).await?; + Ok(connection) } } diff --git a/src/lib.rs b/src/lib.rs index e055421..e2497b8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,10 +57,10 @@ //! let addr = "0.0.0.0:8085"; // Listening address //! println!("Listening on {}", addr); //! let listener = TcpListener::bind(addr).await?; -//! let server = Esl::outbound(listener).await?; //! //! loop { -//! let (socket, _) = server.accept().await?; +//! let (socket, _) = listener.accept().await?; +//! let socket = Esl::outbound(socket).await?; //! tokio::spawn(async move { process_call(socket).await }); //! } //! } @@ -73,7 +73,6 @@ pub(crate) mod error; pub(crate) mod esl; pub(crate) mod event; pub(crate) mod io; -pub(crate) mod outbound; pub use connection::EslConnection; pub use error::*; diff --git a/src/outbound.rs b/src/outbound.rs deleted file mode 100644 index fa74434..0000000 --- a/src/outbound.rs +++ /dev/null @@ -1,20 +0,0 @@ -use std::net::SocketAddr; - -use tokio::net::TcpListener; - -use crate::{connection::EslConnection, EslConnectionType, EslError}; - -pub struct Outbound { - listener: TcpListener, -} -impl Outbound { - pub(crate) async fn new(listener: TcpListener) -> Result { - Ok(Self { listener }) - } - pub async fn accept(&self) -> Result<(EslConnection, SocketAddr), EslError> { - let (stream, addr) = self.listener.accept().await?; - let connection = - EslConnection::with_tcpstream(stream, "None", EslConnectionType::Outbound).await?; - Ok((connection, addr)) - } -}