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

Function main

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

Source from the content-addressed store, hash-verified

58}
59
60int main(int argc, const char** argv)
61{
62 const char* port = argc >= 2 ? argv[1] : "50051";
63 const auto host = std::string("0.0.0.0:") + port;
64 const auto thread_count = std::thread::hardware_concurrency();
65
66 helloworld::Greeter::AsyncService service;
67 std::unique_ptr<grpc::Server> server;
68
69 grpc::ServerBuilder builder;
70 agrpc::GrpcContext grpc_context(builder.AddCompletionQueue(), thread_count);
71 builder.AddListeningPort(host, grpc::InsecureServerCredentials());
72 builder.RegisterService(&service);
73 server = builder.BuildAndStart();
74
75 example::ServerShutdown shutdown{*server, grpc_context};
76
77 // Create one thread per GrpcContext.
78 std::vector<std::thread> threads;
79 for (size_t i = 0; i < thread_count; ++i)
80 {
81 threads.emplace_back(
82 [&]
83 {
84 register_request_handler(grpc_context, service, shutdown);
85 grpc_context.run();
86 });
87 }
88
89 for (auto& thread : threads)
90 {
91 thread.join();
92 }
93}

Callers

nothing calls this directly

Calls 2

register_request_handlerFunction · 0.70
runMethod · 0.45

Tested by

no test coverage detected