| 77 | } // namespace example |
| 78 | |
| 79 | int main(int argc, char* argv[]) { |
| 80 | // Parse gflags. We recommend you to use gflags as well. |
| 81 | GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); |
| 82 | |
| 83 | // Generally you only need one Server. |
| 84 | brpc::Server server; |
| 85 | |
| 86 | // Instance of your service. |
| 87 | example::EchoServiceImpl echo_service_impl; |
| 88 | |
| 89 | // Add the service into server. Notice the second parameter, because the |
| 90 | // service is put on stack, we don't want server to delete it, otherwise |
| 91 | // use brpc::SERVER_OWNS_SERVICE. |
| 92 | if (server.AddService(&echo_service_impl, |
| 93 | brpc::SERVER_DOESNT_OWN_SERVICE) != 0) { |
| 94 | LOG(ERROR) << "Fail to add service"; |
| 95 | return -1; |
| 96 | } |
| 97 | |
| 98 | butil::EndPoint point; |
| 99 | if (!FLAGS_listen_addr.empty()) { |
| 100 | if (butil::str2endpoint(FLAGS_listen_addr.c_str(), &point) < 0) { |
| 101 | LOG(ERROR) << "Invalid listen address:" << FLAGS_listen_addr; |
| 102 | return -1; |
| 103 | } |
| 104 | } else { |
| 105 | point = butil::EndPoint(butil::IP_ANY, FLAGS_port); |
| 106 | } |
| 107 | // Start the server. |
| 108 | brpc::ServerOptions options; |
| 109 | options.idle_timeout_sec = FLAGS_idle_timeout_s; |
| 110 | if (server.Start(point, &options) != 0) { |
| 111 | LOG(ERROR) << "Fail to start EchoServer"; |
| 112 | return -1; |
| 113 | } |
| 114 | |
| 115 | // Wait until Ctrl-C is pressed, then Stop() and Join() the server. |
| 116 | server.RunUntilAskedToQuit(); |
| 117 | return 0; |
| 118 | } |
nothing calls this directly
no test coverage detected