Compare commits
2 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f829f816ba | ||
|
|
f2ed92564c |
2 changed files with 38 additions and 3 deletions
29
.devcontainer/devcontainer.json
Normal file
29
.devcontainer/devcontainer.json
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"name": "Rust Workshop",
|
||||
"image": "mcr.microsoft.com/devcontainers/rust:1-bullseye",
|
||||
"features": {
|
||||
"ghcr.io/devcontainers/features/git:1": {}
|
||||
},
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"rust-lang.rust-analyzer",
|
||||
"vadimcn.vscode-lldb",
|
||||
"tamasfe.even-better-toml",
|
||||
"humao.rest-client"
|
||||
],
|
||||
"settings": {
|
||||
"editor.formatOnSave": true,
|
||||
"rust-analyzer.check.command": "clippy"
|
||||
}
|
||||
}
|
||||
},
|
||||
"postCreateCommand": "cargo build",
|
||||
"forwardPorts": [7878],
|
||||
"portsAttributes": {
|
||||
"7878": {
|
||||
"label": "HTTP Server",
|
||||
"onAutoForward": "notify"
|
||||
}
|
||||
}
|
||||
}
|
||||
12
src/main.rs
12
src/main.rs
|
|
@ -44,6 +44,14 @@ impl ThreadPool {
|
|||
}
|
||||
Self { workers, sender }
|
||||
}
|
||||
|
||||
pub fn execute<F>(&self, f: F)
|
||||
where
|
||||
F: FnOnce() + Send + 'static,
|
||||
{
|
||||
let job = Box::new(f);
|
||||
self.sender.send(job).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
type Job = Box<dyn FnOnce() + Send + 'static>;
|
||||
|
|
@ -54,9 +62,7 @@ fn main() -> std::io::Result<()> {
|
|||
let pool = ThreadPool::new(4);
|
||||
for stream in listener.incoming() {
|
||||
let stream = stream?;
|
||||
thread::spawn(|| {
|
||||
handle_connection(stream).unwrap();
|
||||
});
|
||||
pool.execute(|| handle_connection(stream).unwrap());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue