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

Function main

example/rpcz_echo_c++/server.cpp:133–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131} // namespace example
132
133int main(int argc, char* argv[]) {
134 // Parse gflags. We recommend you to use gflags as well.
135 GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
136
137 // Generally you only need one Server.
138 brpc::Server server;
139
140 // Instance of your service.
141 example::EchoServiceImpl echo_service_impl;
142
143 // Add the service into server. Notice the second parameter, because the
144 // service is put on stack, we don't want server to delete it, otherwise
145 // use brpc::SERVER_OWNS_SERVICE.
146 if (server.AddService(&echo_service_impl, brpc::SERVER_DOESNT_OWN_SERVICE) != 0) {
147 LOG(ERROR) << "Fail to add service";
148 return -1;
149 }
150
151 butil::EndPoint point;
152 if (!FLAGS_listen_addr.empty()) {
153 if (butil::str2endpoint(FLAGS_listen_addr.c_str(), &point) < 0) {
154 LOG(ERROR) << "Invalid listen address:" << FLAGS_listen_addr;
155 return -1;
156 }
157 } else {
158 point = butil::EndPoint(butil::IP_ANY, FLAGS_port);
159 }
160 // Start the server.
161 brpc::ServerOptions options;
162 options.idle_timeout_sec = FLAGS_idle_timeout_s;
163 if (server.Start(point, &options) != 0) {
164 LOG(ERROR) << "Fail to start EchoServer";
165 return -1;
166 }
167
168 // Wait until Ctrl-C is pressed, then Stop() and Join() the server.
169 server.RunUntilAskedToQuit();
170 return 0;
171}

Callers

nothing calls this directly

Calls 7

str2endpointFunction · 0.85
EndPointClass · 0.85
AddServiceMethod · 0.80
RunUntilAskedToQuitMethod · 0.80
emptyMethod · 0.45
c_strMethod · 0.45
StartMethod · 0.45

Tested by

no test coverage detected