| 110 | } // namespace example |
| 111 | |
| 112 | int main(int argc, char* argv[]) { |
| 113 | // Parse gflags. We recommend you to use gflags as well. |
| 114 | GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); |
| 115 | |
| 116 | // Generally you only need one Server. |
| 117 | brpc::Server server; |
| 118 | |
| 119 | butil::EndPoint point; |
| 120 | if (!FLAGS_listen_addr.empty()) { |
| 121 | if (butil::str2endpoint(FLAGS_listen_addr.c_str(), &point) < 0) { |
| 122 | LOG(ERROR) << "Invalid listen address:" << FLAGS_listen_addr; |
| 123 | return -1; |
| 124 | } |
| 125 | } else { |
| 126 | point = butil::EndPoint(butil::IP_ANY, FLAGS_port); |
| 127 | } |
| 128 | // Start the server. |
| 129 | brpc::ServerOptions options; |
| 130 | // Add the baidu master service into server. |
| 131 | // Notice new operator, because server will delete it in dtor of Server. |
| 132 | options.baidu_master_service = new example::BaiduMasterServiceImpl(); |
| 133 | options.idle_timeout_sec = FLAGS_idle_timeout_s; |
| 134 | if (server.Start(point, &options) != 0) { |
| 135 | LOG(ERROR) << "Fail to start EchoServer"; |
| 136 | return -1; |
| 137 | } |
| 138 | |
| 139 | // Wait until Ctrl-C is pressed, then Stop() and Join() the server. |
| 140 | server.RunUntilAskedToQuit(); |
| 141 | return 0; |
| 142 | } |
nothing calls this directly
no test coverage detected