close stream after response send

This commit is contained in:
MeexReay 2024-09-20 14:51:50 +03:00
parent 8c5e10a93e
commit b06518846f
4 changed files with 29 additions and 5 deletions

View File

@ -1,7 +1,9 @@
pub mod config; pub mod config;
pub mod server; pub mod server;
pub mod ssl_cert; pub mod ssl_cert;
pub mod closeable;
pub use config::*; pub use config::*;
pub use server::*; pub use server::*;
pub use ssl_cert::*; pub use ssl_cert::*;
pub use closeable::*;

21
src/flowgate/closeable.rs Normal file
View File

@ -0,0 +1,21 @@
use std::net::{Shutdown, TcpStream};
#[cfg(feature = "use-openssl")]
use openssl::ssl::SslStream;
pub trait Closeable {
fn close(&self);
}
impl Closeable for TcpStream {
fn close(&self) {
let _ = self.shutdown(Shutdown::Both);
}
}
#[cfg(feature = "use-openssl")]
impl<T: Closeable> Closeable for SslStream<T> {
fn close(&self) {
self.get_ref().close();
}
}

View File

@ -3,7 +3,7 @@ use std::{io::{Read, Write}, net::{Shutdown, SocketAddr, TcpListener}, sync::Arc
use log::info; use log::info;
use threadpool::ThreadPool; use threadpool::ThreadPool;
use super::Config; use super::{Closeable, Config};
pub struct FlowgateServer { pub struct FlowgateServer {
config: Arc<Config>, config: Arc<Config>,
@ -179,7 +179,7 @@ impl FlowgateServer {
pub fn accept_stream( pub fn accept_stream(
config: Arc<Config>, config: Arc<Config>,
stream: &mut (impl Read + Write), stream: &mut (impl Read + Write + Closeable),
addr: SocketAddr, addr: SocketAddr,
https: bool https: bool
) -> Option<()> { ) -> Option<()> {
@ -314,7 +314,8 @@ impl FlowgateServer {
} }
} }
site_stream.shutdown(Shutdown::Both).ok()?; site_stream.close();
stream.close();
Some(()) Some(())
} }

View File

@ -108,4 +108,4 @@ impl AdoptedConnection {
} }
} }
// TODO: implement Read and Write to AdoptedConnection // TODO: implement Read and Write and Closeable to AdoptedConnection