limit open connections
This commit is contained in:
parent
9170e7f7f8
commit
0ba58d98e2
1 changed files with 8 additions and 0 deletions
|
@ -5,11 +5,14 @@ use std::{
|
||||||
net::{TcpListener, TcpStream},
|
net::{TcpListener, TcpStream},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
thread,
|
thread,
|
||||||
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod http;
|
mod http;
|
||||||
use http::{Content, Method, Request, RequestRange, Response, Status};
|
use http::{Content, Method, Request, RequestRange, Response, Status};
|
||||||
|
|
||||||
|
const MAX_CONNECTIONS: usize = 256;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
|
|
||||||
|
@ -36,6 +39,11 @@ fn main() {
|
||||||
Err(err) => println!("Error with incoming stream: {err}"),
|
Err(err) => println!("Error with incoming stream: {err}"),
|
||||||
}
|
}
|
||||||
threads.retain(|j| !j.is_finished());
|
threads.retain(|j| !j.is_finished());
|
||||||
|
while threads.len() >= MAX_CONNECTIONS {
|
||||||
|
threads.retain(|j| !j.is_finished());
|
||||||
|
thread::sleep(Duration::from_millis(500));
|
||||||
|
println!("Warning: maximum connections reached ({MAX_CONNECTIONS})")
|
||||||
|
}
|
||||||
println!("{} connections open", threads.len());
|
println!("{} connections open", threads.len());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue