| 224 | } // namespace example |
| 225 | |
| 226 | int main(int argc, char* argv[]) { |
| 227 | // Parse gflags. We recommend you to use gflags as well. |
| 228 | GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); |
| 229 | |
| 230 | // Generally you only need one Server. |
| 231 | brpc::Server server; |
| 232 | |
| 233 | example::HttpServiceImpl http_svc; |
| 234 | example::FileServiceImpl file_svc; |
| 235 | example::QueueServiceImpl queue_svc; |
| 236 | example::HttpSSEServiceImpl sse_svc; |
| 237 | |
| 238 | // Add services into server. Notice the second parameter, because the |
| 239 | // service is put on stack, we don't want server to delete it, otherwise |
| 240 | // use brpc::SERVER_OWNS_SERVICE. |
| 241 | if (server.AddService(&http_svc, |
| 242 | brpc::SERVER_DOESNT_OWN_SERVICE) != 0) { |
| 243 | LOG(ERROR) << "Fail to add http_svc"; |
| 244 | return -1; |
| 245 | } |
| 246 | if (server.AddService(&file_svc, |
| 247 | brpc::SERVER_DOESNT_OWN_SERVICE) != 0) { |
| 248 | LOG(ERROR) << "Fail to add file_svc"; |
| 249 | return -1; |
| 250 | } |
| 251 | if (server.AddService(&queue_svc, |
| 252 | brpc::SERVER_DOESNT_OWN_SERVICE, |
| 253 | "/v1/queue/start => start," |
| 254 | "/v1/queue/stop => stop," |
| 255 | "/v1/queue/stats/* => getstats") != 0) { |
| 256 | LOG(ERROR) << "Fail to add queue_svc"; |
| 257 | return -1; |
| 258 | } |
| 259 | if (server.AddService(&sse_svc, |
| 260 | brpc::SERVER_DOESNT_OWN_SERVICE) != 0) { |
| 261 | LOG(ERROR) << "Fail to add sse_svc"; |
| 262 | return -1; |
| 263 | } |
| 264 | |
| 265 | // Start the server. |
| 266 | brpc::ServerOptions options; |
| 267 | options.idle_timeout_sec = FLAGS_idle_timeout_s; |
| 268 | options.mutable_ssl_options()->default_cert.certificate = FLAGS_certificate; |
| 269 | options.mutable_ssl_options()->default_cert.private_key = FLAGS_private_key; |
| 270 | options.mutable_ssl_options()->ciphers = FLAGS_ciphers; |
| 271 | if (server.Start(FLAGS_port, &options) != 0) { |
| 272 | LOG(ERROR) << "Fail to start HttpServer"; |
| 273 | return -1; |
| 274 | } |
| 275 | |
| 276 | // Wait until Ctrl-C is pressed, then Stop() and Join() the server. |
| 277 | server.RunUntilAskedToQuit(); |
| 278 | return 0; |
| 279 | } |
nothing calls this directly
no test coverage detected