Skip to content

Commit

Permalink
Update wtx
Browse files Browse the repository at this point in the history
  • Loading branch information
c410-f3r committed Sep 20, 2024
1 parent 38875a7 commit cebedd3
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 83 deletions.
109 changes: 41 additions & 68 deletions rust_wtx_bench/Cargo.lock

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

2 changes: 1 addition & 1 deletion rust_wtx_bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ path = "src/main.rs"
[dependencies]
quick-protobuf = { default-features = false, version = "0.8" }
tokio = { default-features = false, features = ["parking_lot", "rt-multi-thread"], version = "1.0" }
wtx = { default-features = false, features = ["grpc", "optimization", "quick-protobuf"], version = "0.17" }
wtx = { default-features = false, features = ["grpc", "optimization", "quick-protobuf"], version = "0.19" }

[build-dependencies]
pb-rs = { default-features = false, version = "0.10" }
Expand Down
27 changes: 13 additions & 14 deletions rust_wtx_bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,33 @@ pub mod grpc_bindings;

use wtx::{
data_transformation::dnsn::QuickProtobuf,
grpc::{GrpcStatusCode, Server, ServerData},
grpc::{GrpcManager, GrpcStatusCode},
http::{
server_framework::{post, Router},
ReqResBuffer, Request, StatusCode,
server_framework::{post, Router, ServerFrameworkBuilder, State},
ReqResBuffer, StatusCode,
},
};

fn main() -> wtx::Result<()> {
let cpus = std::env::var("GRPC_SERVER_CPUS")
.ok()
.and_then(|var| var.parse().ok())
.unwrap_or(1);
tokio::runtime::Builder::new_multi_thread()
.worker_threads(cpus)
.worker_threads(std::env::var("GRPC_SERVER_CPUS")?.parse()?)
.enable_all()
.build()?
.block_on(async move {
let router = Router::paths(wtx::paths!((
"/helloworld.Greeter/SayHello",
post(say_hello)
),));
Server::new(router).listen("0.0.0.0:50051", |_| {}).await
)))?;
ServerFrameworkBuilder::new(router)
.with_req_aux(|| QuickProtobuf::default())
.listen("0.0.0.0:50051", |_| {})
.await
})
}

async fn say_hello(
_: &mut Request<ReqResBuffer>,
_: ServerData<QuickProtobuf>,
) -> wtx::Result<(StatusCode, GrpcStatusCode)> {
Ok((StatusCode::Ok, GrpcStatusCode::Ok))
state: State<'_, (), GrpcManager<QuickProtobuf>, ReqResBuffer>,
) -> wtx::Result<StatusCode> {
*state.ra.status_code_mut() = GrpcStatusCode::Ok;
Ok(StatusCode::Ok)
}

0 comments on commit cebedd3

Please sign in to comment.