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