| 210 | } |
| 211 | |
| 212 | int main(int argc, char* argv[]) { |
| 213 | // Parse gflags. We recommend you to use gflags as well. |
| 214 | GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); |
| 215 | |
| 216 | // The factory to create MySessionLocalData. Must be valid when server is running. |
| 217 | MySessionLocalDataFactory session_local_data_factory; |
| 218 | |
| 219 | MyThreadLocalDataFactory thread_local_data_factory; |
| 220 | |
| 221 | // Generally you only need one Server. |
| 222 | brpc::Server server; |
| 223 | // For more options see `brpc/server.h'. |
| 224 | brpc::ServerOptions options; |
| 225 | options.idle_timeout_sec = FLAGS_idle_timeout_s; |
| 226 | options.max_concurrency = FLAGS_max_concurrency; |
| 227 | options.session_local_data_factory = &session_local_data_factory; |
| 228 | options.thread_local_data_factory = &thread_local_data_factory; |
| 229 | |
| 230 | // Instance of your service. |
| 231 | EchoServiceWithThreadAndSessionLocal echo_service_impl; |
| 232 | |
| 233 | // Add the service into server. Notice the second parameter, because the |
| 234 | // service is put on stack, we don't want server to delete it, otherwise |
| 235 | // use brpc::SERVER_OWNS_SERVICE. |
| 236 | if (server.AddService(&echo_service_impl, |
| 237 | brpc::SERVER_DOESNT_OWN_SERVICE) != 0) { |
| 238 | LOG(ERROR) << "Fail to add service"; |
| 239 | return -1; |
| 240 | } |
| 241 | |
| 242 | // Start the server. |
| 243 | if (server.Start(FLAGS_port, &options) != 0) { |
| 244 | LOG(ERROR) << "Fail to start EchoServer"; |
| 245 | return -1; |
| 246 | } |
| 247 | |
| 248 | // Wait until Ctrl-C is pressed, then Stop() and Join() the server. |
| 249 | server.RunUntilAskedToQuit(); |
| 250 | CHECK_EQ(ntls, 0); |
| 251 | CHECK_EQ(nsd, 0); |
| 252 | return 0; |
| 253 | } |
nothing calls this directly
no test coverage detected