Implement per-stream threading
This commit is contained in:
parent
7ad6eb64b3
commit
8088fcdde6
3 changed files with 31 additions and 28 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -2,4 +2,4 @@
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "herb"
|
name = "herb"
|
||||||
version = "0.1.2"
|
version = "0.1.4"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "herb"
|
name = "herb"
|
||||||
version = "0.1.3"
|
version = "0.2.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use std::io::{Write, BufReader, BufRead};
|
use std::io::{Write, BufReader, BufRead};
|
||||||
|
use std::thread;
|
||||||
use std::net::{TcpListener, TcpStream};
|
use std::net::{TcpListener, TcpStream};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::string::{String};
|
use std::string::{String};
|
||||||
|
@ -183,6 +184,8 @@ fn process_request(request: Vec<u8>) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serve(mut stream: TcpStream) {
|
fn serve(mut stream: TcpStream) {
|
||||||
|
thread::spawn(move || {
|
||||||
|
println!("Stream thread created.");
|
||||||
let mut request = Vec::new();
|
let mut request = Vec::new();
|
||||||
let mut reader = BufReader::new(&mut stream);
|
let mut reader = BufReader::new(&mut stream);
|
||||||
reader
|
reader
|
||||||
|
@ -198,7 +201,7 @@ fn serve(mut stream: TcpStream) {
|
||||||
let contents = get_page(resource);
|
let contents = get_page(resource);
|
||||||
let header = "HTTP/1.1 200 OK\r\n";
|
let header = "HTTP/1.1 200 OK\r\n";
|
||||||
let content_type = format!("Content-Type: {}\r\n", mime);
|
let content_type = format!("Content-Type: {}\r\n", mime);
|
||||||
let server = "Server: Herb/0.1.4\r\n";
|
let server = "Server: Herb/0.2.0\r\n";
|
||||||
let extra_fields;
|
let extra_fields;
|
||||||
|
|
||||||
if cfg!(unix) {
|
if cfg!(unix) {
|
||||||
|
@ -216,7 +219,7 @@ fn serve(mut stream: TcpStream) {
|
||||||
|
|
||||||
stream.write(response.as_bytes()).unwrap();
|
stream.write(response.as_bytes()).unwrap();
|
||||||
stream.flush().unwrap();
|
stream.flush().unwrap();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue