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

Function register_request_handler

example/multi-threaded-server.cpp:37–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.70

Calls 3

moveFunction · 0.85
finishMethod · 0.45
shutdownMethod · 0.45

Tested by

no test coverage detected