From 9d1e5f1d21ffed8f29b42e81c6ac611afb0f4227 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Sun, 17 May 2020 09:46:06 -0700 Subject: [PATCH] WIP: Basic echo --- src/main.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0204791..65ee2ae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,14 +11,19 @@ use { std::{ error::Error, fs::File, - io::BufReader, + io::{BufReader, self}, sync::Arc, }, }; pub type Result = std::result::Result>; -async fn handle_connection(_: TlsAcceptor, _: TcpStream) { +async fn connection(acceptor: TlsAcceptor, stream: TcpStream) -> io::Result<()> { + let mut stream = acceptor.accept(stream).await?; + let mut body = Vec::new(); + stream.read_to_end(&mut body).await?; + stream.write_all(&body).await?; + Ok(()) } fn main() -> Result { @@ -41,7 +46,9 @@ fn main() -> Result { let acceptor = acceptor.clone(); let stream = stream?; task::spawn(async { - handle_connection(acceptor, stream).await; + if let Err(e) = connection(acceptor, stream).await { + eprintln!("Error: {:?}", e); + } }); }