close stream after response send
This commit is contained in:
parent
8c5e10a93e
commit
b06518846f
@ -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
21
src/flowgate/closeable.rs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
@ -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(())
|
||||||
}
|
}
|
||||||
|
@ -108,4 +108,4 @@ impl AdoptedConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: implement Read and Write to AdoptedConnection
|
// TODO: implement Read and Write and Closeable to AdoptedConnection
|
Loading…
Reference in New Issue
Block a user