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

Method Echo

example/rpcz_echo_c++/server.cpp:91–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89 EchoServiceImpl() {}
90 virtual ~EchoServiceImpl() {}
91 virtual void Echo(google::protobuf::RpcController* cntl_base, const EchoRequest* request,
92 EchoResponse* response, google::protobuf::Closure* done) {
93 bthread_list_t list;
94 bthread_list_init(&list, 0, 0);
95 for (int i = 0; i < 2; ++i) {
96 bthread_t tid;
97 bthread_start_background(&tid, &BTHREAD_ATTR_NORMAL_WITH_SPAN, RunThreadFunc, nullptr);
98 bthread_list_add(&list, tid);
99 }
100 bthread_list_join(&list);
101
102 TRACEPRINTF("Handle request");
103
104 // This object helps you to call done->Run() in RAII style. If you need
105 // to process the request asynchronously, pass done_guard.release().
106 brpc::ClosureGuard done_guard(done);
107
108 brpc::Controller* cntl = static_cast<brpc::Controller*>(cntl_base);
109
110 // The purpose of following logs is to help you to understand
111 // how clients interact with servers more intuitively. You should
112 // remove these logs in performance-sensitive servers.
113 LOG(INFO) << "Received request[log_id=" << cntl->log_id() << "] from "
114 << cntl->remote_side() << " to " << cntl->local_side() << ": "
115 << request->message() << " (attached=" << cntl->request_attachment() << ")";
116
117 // Fill response.
118 response->set_message(request->message());
119
120 // You can compress the response by setting Controller, but be aware
121 // that compression may be costly, evaluate before turning on.
122 // cntl->set_response_compress_type(brpc::COMPRESS_TYPE_GZIP);
123
124 if (FLAGS_echo_attachment) {
125 // Set attachment which is wired to network directly instead of
126 // being serialized into protobuf messages.
127 cntl->response_attachment().append(cntl->request_attachment());
128 }
129 }
130};
131} // namespace example
132

Callers 2

mainFunction · 0.45
RunThreadFuncFunction · 0.45

Calls 9

bthread_list_initFunction · 0.85
bthread_start_backgroundFunction · 0.85
bthread_list_addFunction · 0.85
bthread_list_joinFunction · 0.85
log_idMethod · 0.45
remote_sideMethod · 0.45
local_sideMethod · 0.45
messageMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected