Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add threading support. #4

Merged
merged 5 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
228 changes: 228 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ fn main() {
```

# Roadmap
- [ ] A single-thread blocking version
- [ ] A thread pool version
- [x] A single-thread blocking version
- [x] A thread pool version
- [ ] A non-blocking single-thread version
- [ ] A complete HTTP/1 and HTTP/1.1 parser
- [ ] TLS
Expand Down
1 change: 1 addition & 0 deletions example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ version = "0.1.0"
edition = "2021"

[dependencies]
clap = { version = "4.5.19", features = ["derive"] }
http = { path = "../http" }

20 changes: 19 additions & 1 deletion example/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use clap::Parser;
use http::{
request::{Method, Request},
response::{Headers, Response, Status},
Expand Down Expand Up @@ -55,7 +56,24 @@ fn headers(request: &mut Request) -> Response {
},
}
}

#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
/// Thread pool size (enable threading with --threading)
#[arg(short = 'c', long, default_value_t = 50)]
threads_count: usize,

#[arg(short, long)]
threaded: bool,
}

fn main() {
let server = Server::new("0.0.0.0:4000", headers);
let args = Args::parse();
let server = if args.threaded {
Server::threaded("0.0.0.0:4000", headers, args.threads_count)
} else {
Server::new("0.0.0.0:4000", headers)
};
server.listen().unwrap();
}
1 change: 1 addition & 0 deletions http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
pub mod request;
pub mod response;
pub mod server;
pub mod threadpool;
Loading
Loading