MCPcopy Create free account
hub / github.com/apache/brpc / main

Function main

example/coroutine/coroutine_server.cpp:110–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108} // namespace example
109
110int 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}

Callers

nothing calls this directly

Calls 4

bthread_setconcurrencyFunction · 0.85
AddServiceMethod · 0.80
RunUntilAskedToQuitMethod · 0.80
StartMethod · 0.45

Tested by

no test coverage detected