-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
39 lines (33 loc) · 844 Bytes
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
mod thread_pool;
mod connection;
mod responses;
mod macros;
use crate::{
thread_pool::ThreadPool,
connection::handle_connection
};
use std::net::{
TcpListener, TcpStream
};
// ==================== Main ====================
fn main() {
let listener: TcpListener = match TcpListener::bind("0.0.0.0:7878") {
Ok(listener) => listener,
Err(_) => {
println!("Failed bind to 0.0.0.0:7878");
return;
}
};
let pool: ThreadPool = ThreadPool::new(4);
println!("Starting the server");
for stream in listener.incoming() {
let stream: TcpStream = match stream {
Ok(stream) => stream,
Err(_) => {continue;}
};
pool.execute(|| {
handle_connection(stream);
});
}
println!("Shutting down");
}