timeout and threadpool settings
This commit is contained in:
parent
d815fa6ead
commit
1b7616be8d
21
conf.yml
21
conf.yml
@ -1,17 +1,12 @@
|
||||
http_host: localhost:80 # Http 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:
|
||||
# - domain: example.com # Domain with SSL
|
||||
# host: localhost:8080 # Http server host
|
||||
# ssl_cert: "/path/to/public/certificate.txt" # Ssl public certificate file
|
||||
# ssl_key: "/path/to/private/key.txt" # Ssl private key file
|
||||
# support_keep_alive: true # Does server supports keep-alive connections
|
||||
|
||||
# - 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
|
||||
- domain: localhost # Site domain
|
||||
host: localhost:8080 # Http server host
|
||||
support_keep_alive: false # Does server supports keep-alive connections
|
||||
# ssl_cert: "/path/to/public/certificate.txt" # Ssl public certificate file (optional)
|
||||
# ssl_key: "/path/to/private/key.txt" # Ssl private key file (optional)
|
||||
|
@ -1,4 +1,4 @@
|
||||
use std::{fs, net::TcpStream, sync::Arc};
|
||||
use std::{fs, net::TcpStream, sync::Arc, time::Duration};
|
||||
|
||||
use serde_yml::Value;
|
||||
|
||||
@ -23,6 +23,8 @@ pub struct Config {
|
||||
pub sites: Arc<Vec<SiteConfig>>,
|
||||
pub http_host: String,
|
||||
pub https_host: String,
|
||||
pub threadpool_size: usize,
|
||||
pub connection_timeout: Duration
|
||||
}
|
||||
|
||||
impl Config {
|
||||
@ -33,6 +35,9 @@ impl Config {
|
||||
let http_host = doc["http_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 sites_yaml = doc["sites"].as_sequence()?;
|
||||
@ -60,10 +65,14 @@ impl Config {
|
||||
sites.push(site);
|
||||
}
|
||||
|
||||
let sites = Arc::new(sites);
|
||||
|
||||
Some(Config {
|
||||
sites: Arc::new(sites),
|
||||
sites,
|
||||
http_host,
|
||||
https_host,
|
||||
threadpool_size,
|
||||
connection_timeout
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ impl FlowgateServer {
|
||||
|
||||
let cert = cert.build();
|
||||
|
||||
let pool = ThreadPool::new(10);
|
||||
let pool = ThreadPool::new(config.threadpool_size);
|
||||
|
||||
info!("HTTPS server runned on {}", &config.https_host);
|
||||
|
||||
@ -100,9 +100,9 @@ impl FlowgateServer {
|
||||
|
||||
move || {
|
||||
let Ok(stream) = stream else { return };
|
||||
|
||||
let Ok(_) = stream.set_write_timeout(Some(Duration::from_secs(10))) else { return };
|
||||
let Ok(_) = stream.set_read_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(config.connection_timeout)) else { return };
|
||||
|
||||
let Ok(addr) = stream.peer_addr() else { return };
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user