| 51 | }; |
| 52 | |
| 53 | int main(int argc, char* argv[]) { |
| 54 | // Parse gflags. We recommend you to use gflags as well. |
| 55 | GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); |
| 56 | |
| 57 | // Generally you only need one Server. |
| 58 | brpc::Server server; |
| 59 | |
| 60 | // Instance of your service. |
| 61 | EchoServiceImpl echo_service_impl; |
| 62 | |
| 63 | // Add the service into server. Notice the second parameter, because the |
| 64 | // service is put on stack, we don't want server to delete it, otherwise |
| 65 | // use brpc::SERVER_OWNS_SERVICE. |
| 66 | if (server.AddService(&echo_service_impl, |
| 67 | brpc::SERVER_DOESNT_OWN_SERVICE) != 0) { |
| 68 | LOG(ERROR) << "Fail to add service"; |
| 69 | return -1; |
| 70 | } |
| 71 | |
| 72 | // Start the server. |
| 73 | brpc::ServerOptions options; |
| 74 | options.idle_timeout_sec = FLAGS_idle_timeout_s; |
| 75 | options.max_concurrency = FLAGS_max_concurrency; |
| 76 | if (server.Start(FLAGS_port, &options) != 0) { |
| 77 | LOG(ERROR) << "Fail to start EchoServer"; |
| 78 | return -1; |
| 79 | } |
| 80 | |
| 81 | // Wait until Ctrl-C is pressed, then Stop() and Join() the server. |
| 82 | server.RunUntilAskedToQuit(); |
| 83 | return 0; |
| 84 | } |
nothing calls this directly
no test coverage detected