Fixed clean shutdown

This commit is contained in:
int 80h
2021-11-15 21:32:23 -05:00
parent 76a5dabe94
commit 077357e0d9
3 changed files with 7 additions and 3 deletions

2
Cargo.lock generated
View File

@@ -140,7 +140,7 @@ dependencies = [
[[package]] [[package]]
name = "gemserv" name = "gemserv"
version = "0.4.6" version = "0.4.7"
dependencies = [ dependencies = [
"futures-util", "futures-util",
"log", "log",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "gemserv" name = "gemserv"
version = "0.4.6" version = "0.4.7"
authors = ["int 80h <int@80h.dev>"] authors = ["int 80h <int@80h.dev>"]
edition = "2018" edition = "2018"
description = "A gemini server" description = "A gemini server"

View File

@@ -4,7 +4,7 @@ use std::net::SocketAddr;
use tokio::net::TcpStream; use tokio::net::TcpStream;
use tokio::io::AsyncRead; use tokio::io::AsyncRead;
use tokio::io::AsyncWriteExt; use tokio::io::{AsyncWrite, AsyncWriteExt};
use tokio_openssl::SslStream; use tokio_openssl::SslStream;
use crate::status::Status; use crate::status::Status;
@@ -35,6 +35,9 @@ impl Connection {
if let Some(b) = body { if let Some(b) = body {
self.send_raw(b.as_bytes()).await?; self.send_raw(b.as_bytes()).await?;
} }
futures_util::future::poll_fn(|ctx| std::pin::Pin::new(&mut self.stream).poll_shutdown(ctx)).await.unwrap();
Ok(()) Ok(())
} }
@@ -46,6 +49,7 @@ impl Connection {
pub async fn send_stream<S: AsyncRead + Unpin>(&mut self, reader: &mut S) -> Result<(), io::Error> { pub async fn send_stream<S: AsyncRead + Unpin>(&mut self, reader: &mut S) -> Result<(), io::Error> {
tokio::io::copy(reader, &mut self.stream).await?; tokio::io::copy(reader, &mut self.stream).await?;
futures_util::future::poll_fn(|ctx| std::pin::Pin::new(&mut self.stream).poll_shutdown(ctx)).await.unwrap();
Ok(()) Ok(())
} }
} }