| 99 | } // namespace example |
| 100 | |
| 101 | int main(int argc, char* argv[]) { |
| 102 | // Parse gflags. We recommend you to use gflags as well. |
| 103 | GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); |
| 104 | |
| 105 | // Generally you only need one Server. |
| 106 | brpc::Server server; |
| 107 | |
| 108 | // Instance of your service. |
| 109 | example::EchoServiceImpl echo_service_impl; |
| 110 | |
| 111 | // Add the service into server. Notice the second parameter, because the |
| 112 | // service is put on stack, we don't want server to delete it, otherwise |
| 113 | // use brpc::SERVER_OWNS_SERVICE. |
| 114 | if (server.AddService(&echo_service_impl, |
| 115 | brpc::SERVER_DOESNT_OWN_SERVICE) != 0) { |
| 116 | LOG(ERROR) << "Fail to add service"; |
| 117 | return -1; |
| 118 | } |
| 119 | |
| 120 | butil::EndPoint point; |
| 121 | if (!FLAGS_listen_addr.empty()) { |
| 122 | if (butil::str2endpoint(FLAGS_listen_addr.c_str(), &point) < 0) { |
| 123 | LOG(ERROR) << "Invalid listen address:" << FLAGS_listen_addr; |
| 124 | return -1; |
| 125 | } |
| 126 | } else { |
| 127 | point = butil::EndPoint(butil::IP_ANY, FLAGS_port); |
| 128 | } |
| 129 | // Start the server. |
| 130 | brpc::ServerOptions options; |
| 131 | options.idle_timeout_sec = FLAGS_idle_timeout_s; |
| 132 | if (server.Start(point, &options) != 0) { |
| 133 | LOG(ERROR) << "Fail to start EchoServer"; |
| 134 | return -1; |
| 135 | } |
| 136 | |
| 137 | // Wait until Ctrl-C is pressed, then Stop() and Join() the server. |
| 138 | server.RunUntilAskedToQuit(); |
| 139 | return 0; |
| 140 | } |
nothing calls this directly
no test coverage detected