| 58 | } |
| 59 | |
| 60 | int 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 | } |
nothing calls this directly
no test coverage detected