| 242 | using ShutdownRPC = agrpc::ServerRPC<&ExampleExtService::RequestShutdown>; |
| 243 | |
| 244 | int main(int argc, const char** argv) |
| 245 | { |
| 246 | const char* port = argc >= 2 ? argv[1] : "50051"; |
| 247 | const auto host = std::string("0.0.0.0:") + port; |
| 248 | |
| 249 | std::unique_ptr<grpc::Server> server; |
| 250 | |
| 251 | grpc::ServerBuilder builder; |
| 252 | agrpc::GrpcContext grpc_context{builder.AddCompletionQueue()}; |
| 253 | builder.AddListeningPort(host, grpc::InsecureServerCredentials()); |
| 254 | ExampleService service; |
| 255 | builder.RegisterService(&service); |
| 256 | ExampleExtService service_ext; |
| 257 | builder.RegisterService(&service_ext); |
| 258 | server = builder.BuildAndStart(); |
| 259 | abort_if_not(bool{server}); |
| 260 | |
| 261 | example::ServerShutdown server_shutdown{*server, grpc_context}; |
| 262 | |
| 263 | asio::thread_pool thread_pool{1}; |
| 264 | |
| 265 | agrpc::register_awaitable_rpc_handler<ClientStreamingRPC>(grpc_context, service, &handle_client_streaming_request, |
| 266 | example::RethrowFirstArg{}); |
| 267 | |
| 268 | agrpc::register_awaitable_rpc_handler<ServerStreamingRPC>(grpc_context, service, &handle_server_streaming_request, |
| 269 | example::RethrowFirstArg{}); |
| 270 | |
| 271 | agrpc::register_awaitable_rpc_handler<ServerStreamingNotifyWhenDoneRPC>( |
| 272 | grpc_context, service_ext, server_streaming_notify_when_done_request_handler(grpc_context), |
| 273 | example::RethrowFirstArg{}); |
| 274 | |
| 275 | agrpc::register_awaitable_rpc_handler<BidiStreamingRPC>( |
| 276 | grpc_context, service, bidirectional_streaming_rpc_handler(thread_pool), example::RethrowFirstArg{}); |
| 277 | |
| 278 | agrpc::register_awaitable_rpc_handler<SlowUnaryRPC>(grpc_context, service_ext, &handle_slow_unary_request, |
| 279 | example::RethrowFirstArg{}); |
| 280 | |
| 281 | agrpc::register_awaitable_rpc_handler<ShutdownRPC>( |
| 282 | grpc_context, service_ext, |
| 283 | [&](ShutdownRPC& rpc, const ShutdownRPC::Request&) -> asio::awaitable<void> |
| 284 | { |
| 285 | if (co_await rpc.finish({}, grpc::Status::OK)) |
| 286 | { |
| 287 | std::cout << "Received shutdown request from client\n"; |
| 288 | server_shutdown.shutdown(); |
| 289 | } |
| 290 | }, |
| 291 | example::RethrowFirstArg{}); |
| 292 | |
| 293 | grpc_context.run(); |
| 294 | std::cout << "Shutdown completed\n"; |
| 295 | } |
nothing calls this directly
no test coverage detected