agate

Simple gemini server for static files
git clone https://github.com/mbrubeck/agate.git
Log | Files | Refs | README

commit 9d1e5f1d21ffed8f29b42e81c6ac611afb0f4227
parent 45faee45a7a3c88050df3cd0f3e7ec9744d8c8db
Author: Matt Brubeck <mbrubeck@limpet.net>
Date:   Sun, 17 May 2020 09:46:06 -0700

WIP: Basic echo

Diffstat:
Msrc/main.rs | 13++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git 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<T=()> = std::result::Result<T, Box<dyn Error>>; -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); + } }); }