timeout and threadpool settings

This commit is contained in:
MeexReay 2024-09-14 15:09:08 +03:00
parent d815fa6ead
commit 1b7616be8d
3 changed files with 23 additions and 19 deletions

View File

@ -1,17 +1,12 @@
http_host: localhost:80 # Http server host http_host: localhost:80 # Http server host
https_host: localhost:443 # Https server host https_host: localhost:443 # Https server host
threadpool_size: 10 # Threadpool size (count of threads that accept requests)
connection_timeout: 10 # Read and write timeout of connections in seconds
sites: sites:
# - domain: example.com # Domain with SSL - domain: localhost # Site domain
# host: localhost:8080 # Http server host host: localhost:8080 # Http server host
# ssl_cert: "/path/to/public/certificate.txt" # Ssl public certificate file support_keep_alive: false # Does server supports keep-alive connections
# ssl_key: "/path/to/private/key.txt" # Ssl private key file # ssl_cert: "/path/to/public/certificate.txt" # Ssl public certificate file (optional)
# support_keep_alive: true # Does server supports keep-alive connections # ssl_key: "/path/to/private/key.txt" # Ssl private key file (optional)
# - domain: sub.example.com # Domain with no SSL
# host: localhost:8081 # Http server host
# support_keep_alive: true # Does server supports keep-alive connections
- domain: localhost
host: localhost:8080
support_keep_alive: false

View File

@ -1,4 +1,4 @@
use std::{fs, net::TcpStream, sync::Arc}; use std::{fs, net::TcpStream, sync::Arc, time::Duration};
use serde_yml::Value; use serde_yml::Value;
@ -23,6 +23,8 @@ pub struct Config {
pub sites: Arc<Vec<SiteConfig>>, pub sites: Arc<Vec<SiteConfig>>,
pub http_host: String, pub http_host: String,
pub https_host: String, pub https_host: String,
pub threadpool_size: usize,
pub connection_timeout: Duration
} }
impl Config { impl Config {
@ -33,6 +35,9 @@ impl Config {
let http_host = doc["http_host"].as_str()?.to_string(); let http_host = doc["http_host"].as_str()?.to_string();
let https_host = doc["https_host"].as_str()?.to_string(); let https_host = doc["https_host"].as_str()?.to_string();
let threadpool_size = doc["threadpool_size"].as_u64()? as usize;
let connection_timeout = Duration::from_secs(doc["connection_timeout"].as_u64()?);
let mut sites: Vec<SiteConfig> = Vec::new(); let mut sites: Vec<SiteConfig> = Vec::new();
let sites_yaml = doc["sites"].as_sequence()?; let sites_yaml = doc["sites"].as_sequence()?;
@ -60,10 +65,14 @@ impl Config {
sites.push(site); sites.push(site);
} }
let sites = Arc::new(sites);
Some(Config { Some(Config {
sites: Arc::new(sites), sites,
http_host, http_host,
https_host, https_host,
threadpool_size,
connection_timeout
}) })
} }

View File

@ -89,7 +89,7 @@ impl FlowgateServer {
let cert = cert.build(); let cert = cert.build();
let pool = ThreadPool::new(10); let pool = ThreadPool::new(config.threadpool_size);
info!("HTTPS server runned on {}", &config.https_host); info!("HTTPS server runned on {}", &config.https_host);
@ -101,8 +101,8 @@ impl FlowgateServer {
move || { move || {
let Ok(stream) = stream else { return }; let Ok(stream) = stream else { return };
let Ok(_) = stream.set_write_timeout(Some(Duration::from_secs(10))) else { return }; let Ok(_) = stream.set_write_timeout(Some(config.connection_timeout)) else { return };
let Ok(_) = stream.set_read_timeout(Some(Duration::from_secs(10))) else { return }; let Ok(_) = stream.set_read_timeout(Some(config.connection_timeout)) else { return };
let Ok(addr) = stream.peer_addr() else { return }; let Ok(addr) = stream.peer_addr() else { return };