Implement per-stream threading

This commit is contained in:
abbie 2021-12-24 21:30:39 +00:00
parent 7ad6eb64b3
commit 8088fcdde6
No known key found for this signature in database
GPG key ID: 04DDE463F9200F87
3 changed files with 31 additions and 28 deletions

2
Cargo.lock generated
View file

@ -2,4 +2,4 @@
# It is not intended for manual editing.
[[package]]
name = "herb"
version = "0.1.2"
version = "0.1.4"

View file

@ -1,6 +1,6 @@
[package]
name = "herb"
version = "0.1.3"
version = "0.2.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -1,4 +1,5 @@
use std::io::{Write, BufReader, BufRead};
use std::thread;
use std::net::{TcpListener, TcpStream};
use std::fs;
use std::string::{String};
@ -183,6 +184,8 @@ fn process_request(request: Vec<u8>) -> String {
}
fn serve(mut stream: TcpStream) {
thread::spawn(move || {
println!("Stream thread created.");
let mut request = Vec::new();
let mut reader = BufReader::new(&mut stream);
reader
@ -198,7 +201,7 @@ fn serve(mut stream: TcpStream) {
let contents = get_page(resource);
let header = "HTTP/1.1 200 OK\r\n";
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;
if cfg!(unix) {
@ -216,7 +219,7 @@ fn serve(mut stream: TcpStream) {
stream.write(response.as_bytes()).unwrap();
stream.flush().unwrap();
});
}