parent
24f0ca7de1
commit
bbf889e72e
1 changed files with 9 additions and 5 deletions
10
src/main.rs
10
src/main.rs
|
|
@ -1,12 +1,14 @@
|
||||||
use log::info;
|
use log::info;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::net::{TcpListener, TcpStream};
|
use std::net::{TcpListener, TcpStream};
|
||||||
use std::thread;
|
use std::sync::mpsc;
|
||||||
|
use std::{sync, thread};
|
||||||
|
|
||||||
static GET: &'static [u8] = b"GET / HTTP/1.1\r\n";
|
static GET: &'static [u8] = b"GET / HTTP/1.1\r\n";
|
||||||
|
|
||||||
pub struct ThreadPool {
|
pub struct ThreadPool {
|
||||||
workers: Vec<Worker>,
|
workers: Vec<Worker>,
|
||||||
|
sender: mpsc::Sender<Job>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Worker {
|
struct Worker {
|
||||||
|
|
@ -30,13 +32,15 @@ impl ThreadPool {
|
||||||
pub fn new(size: usize) -> Self {
|
pub fn new(size: usize) -> Self {
|
||||||
assert!(size > 0);
|
assert!(size > 0);
|
||||||
let mut workers = Vec::with_capacity(size);
|
let mut workers = Vec::with_capacity(size);
|
||||||
|
let (sender, receiver) = mpsc::channel();
|
||||||
for id in 0..size {
|
for id in 0..size {
|
||||||
workers.push(Worker::new(id))
|
workers.push(Worker::new(id))
|
||||||
}
|
}
|
||||||
Self {workers}
|
Self { workers, sender }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
struct Job {}
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue