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

Function main

example/cascade_echo_c++/server.cpp:86–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84} // namespace example
85
86int main(int argc, char* argv[]) {
87 // Parse gflags. We recommend you to use gflags as well.
88 GFLAGS_NAMESPACE::SetUsageMessage("A server that may call itself");
89 GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
90
91 // A Channel represents a communication line to a Server. Notice that
92 // Channel is thread-safe and can be shared by all threads in your program.
93 brpc::ChannelOptions coption;
94 if (FLAGS_use_http) {
95 coption.protocol = brpc::PROTOCOL_HTTP;
96 }
97
98 // Initialize the channel, NULL means using default options.
99 // options, see `brpc/channel.h'.
100 if (FLAGS_server.empty()) {
101 if (channel.Init("localhost", FLAGS_port, &coption) != 0) {
102 LOG(ERROR) << "Fail to initialize channel";
103 return -1;
104 }
105 } else {
106 if (channel.Init(FLAGS_server.c_str(), FLAGS_load_balancer.c_str(), &coption) != 0) {
107 LOG(ERROR) << "Fail to initialize channel";
108 return -1;
109 }
110 }
111
112 // Generally you only need one Server.
113 brpc::Server server;
114 // For more options see `brpc/server.h'.
115 brpc::ServerOptions options;
116 options.idle_timeout_sec = FLAGS_idle_timeout_s;
117
118 // Instance of your service.
119 example::CascadeEchoService echo_service_impl;
120
121 // Add the service into server. Notice the second parameter, because the
122 // service is put on stack, we don't want server to delete it, otherwise
123 // use brpc::SERVER_OWNS_SERVICE.
124 if (server.AddService(&echo_service_impl,
125 brpc::SERVER_DOESNT_OWN_SERVICE) != 0) {
126 LOG(ERROR) << "Fail to add service";
127 return -1;
128 }
129
130 // Start the server.
131 if (server.Start(FLAGS_port, &options) != 0) {
132 LOG(ERROR) << "Fail to start EchoServer";
133 return -1;
134 }
135
136 // Wait until Ctrl-C is pressed, then Stop() and Join() the server.
137 server.RunUntilAskedToQuit();
138 return 0;
139}

Callers

nothing calls this directly

Calls 6

AddServiceMethod · 0.80
RunUntilAskedToQuitMethod · 0.80
emptyMethod · 0.45
InitMethod · 0.45
c_strMethod · 0.45
StartMethod · 0.45

Tested by

no test coverage detected