MCPcopy Create free account
hub / github.com/Tradias/asio-grpc / register_request_handler

Function register_request_handler

example/multi-threaded-alternative-server.cpp:35–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33// end-snippet
34
35void register_request_handler(agrpc::GrpcContext& grpc_context, helloworld::Greeter::AsyncService& service,
36 example::ServerShutdown& shutdown)
37{
38 using RPC = agrpc::ServerRPC<&helloworld::Greeter::AsyncService::RequestSayHello>;
39 agrpc::register_callback_rpc_handler<RPC>(
40 grpc_context, service,
41 [&](RPC::Ptr ptr, helloworld::HelloRequest& request)
42 {
43 helloworld::HelloReply response;
44 response.set_message("Hello " + request.name());
45 auto& rpc = *ptr;
46 rpc.finish(response, grpc::Status::OK,
47 [&, p = std::move(ptr)](bool)
48 {
49 // In this example we shut down the server after 20 requests
50 static std::atomic_int counter{};
51 if (19 == counter.fetch_add(1))
52 {
53 shutdown.shutdown();
54 }
55 });
56 },
57 example::RethrowFirstArg{});
58}
59
60int main(int argc, const char** argv)
61{

Callers 1

mainFunction · 0.70

Calls 3

moveFunction · 0.85
finishMethod · 0.45
shutdownMethod · 0.45

Tested by

no test coverage detected