thread_pool_pre 0.1.0

A Thread Pool Preview For Muti Thread to do our task.
Documentation
/*
 * @Author:axiong 
 * @Date: 2022-10-19 22:59:50
 * @LastEditors: raojianxiong 1611420064@qq.com
 * @LastEditTime: 2022-10-20 23:34:44
 * @FilePath: \web\src\main.rs
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
use std::{
    thread,
    fs,
    io::{Read, Write},
    net::{TcpListener, TcpStream},
};

use thread_pool_pre::ThreadPool;
fn main() {
    let listener = TcpListener::bind("127.0.0.1:7878").unwrap();
    let pool = ThreadPool::new(4);
    //依次处理每个请求
    for stream in listener.incoming() {
        let _stream = stream.unwrap();
        pool.execute(||{
            handle_connection(_stream);
        });
        thread::spawn(||{});
    }
}
fn handle_connection(mut stream: TcpStream) {
    let mut buffer = [0; 512];
    stream.read(&mut buffer).unwrap();
    println!("Request:{}", String::from_utf8_lossy(&buffer[..]));

    let get = b"GET / HTTP/1.1\r\n";
    let(status_line, filename) = if buffer.starts_with(get) {
        ("HTTP/1.1 200 OK\r\n\r\n{}", "hello.html")
    }else{
        ("HTTP/1.1 404 NOT FOUND\r\n\r\n", "404.html")
    };
    let contents = fs::read_to_string(filename).unwrap();
    let response = format!("{}{}", status_line, contents);
    stream.write(response.as_bytes()).unwrap();
    stream.flush().unwrap();
   
}