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

Function main

example/multi_threaded_echo_c++/server.cpp:57–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55DEFINE_bool(h, false, "print help information");
56
57int main(int argc, char* argv[]) {
58 std::string help_str = "dummy help infomation";
59 GFLAGS_NAMESPACE::SetUsageMessage(help_str);
60
61 // Parse gflags. We recommend you to use gflags as well.
62 GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
63
64 if (FLAGS_h) {
65 fprintf(stderr, "%s\n%s\n%s", help_str.c_str(), help_str.c_str(), help_str.c_str());
66 return 0;
67 }
68
69 // Generally you only need one Server.
70 brpc::Server server;
71
72 // Instance of your service.
73 example::EchoServiceImpl echo_service_impl;
74
75 // Add the service into server. Notice the second parameter, because the
76 // service is put on stack, we don't want server to delete it, otherwise
77 // use brpc::SERVER_OWNS_SERVICE.
78 if (server.AddService(&echo_service_impl,
79 brpc::SERVER_DOESNT_OWN_SERVICE) != 0) {
80 LOG(ERROR) << "Fail to add service";
81 return -1;
82 }
83
84 // Start the server.
85 brpc::ServerOptions options;
86 options.mutable_ssl_options()->default_cert.certificate = "cert.pem";
87 options.mutable_ssl_options()->default_cert.private_key = "key.pem";
88 options.idle_timeout_sec = FLAGS_idle_timeout_s;
89 options.max_concurrency = FLAGS_max_concurrency;
90 options.internal_port = FLAGS_internal_port;
91 if (server.Start(FLAGS_port, &options) != 0) {
92 LOG(ERROR) << "Fail to start EchoServer";
93 return -1;
94 }
95
96 // Wait until Ctrl-C is pressed, then Stop() and Join() the server.
97 server.RunUntilAskedToQuit();
98 return 0;
99}

Callers

nothing calls this directly

Calls 5

AddServiceMethod · 0.80
RunUntilAskedToQuitMethod · 0.80
c_strMethod · 0.45
mutable_ssl_optionsMethod · 0.45
StartMethod · 0.45

Tested by

no test coverage detected