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

Method Echo

example/cascade_echo_c++/server.cpp:43–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41 CascadeEchoService() {}
42 virtual ~CascadeEchoService() {}
43 virtual void Echo(google::protobuf::RpcController* cntl_base,
44 const EchoRequest* request,
45 EchoResponse* response,
46 google::protobuf::Closure* done) {
47 // This object helps you to call done->Run() in RAII style. If you need
48 // to process the request asynchronously, pass done_guard.release().
49 brpc::ClosureGuard done_guard(done);
50
51 brpc::Controller* cntl =
52 static_cast<brpc::Controller*>(cntl_base);
53
54 if (request->depth() > 0) {
55 CLOGI(cntl) << "I'm about to call myself for another time, depth=" << request->depth();
56 example::EchoService_Stub stub(&channel);
57 example::EchoRequest request2;
58 example::EchoResponse response2;
59 brpc::Controller cntl2(cntl->inheritable());
60 request2.set_message(request->message());
61 request2.set_depth(request->depth() - 1);
62
63 cntl2.set_timeout_ms(FLAGS_timeout_ms);
64 cntl2.set_max_retry(FLAGS_max_retry);
65 stub.Echo(&cntl2, &request2, &response2, NULL);
66 if (cntl2.Failed()) {
67 CLOGE(&cntl2) << "Fail to send EchoRequest, " << cntl2.ErrorText();
68 cntl->SetFailed(cntl2.ErrorCode(), "%s", cntl2.ErrorText().c_str());
69 return;
70 }
71 response->set_message(response2.message());
72 } else {
73 CLOGI(cntl) << "I'm the last call";
74 response->set_message(request->message());
75 }
76
77 if (FLAGS_echo_attachment && !FLAGS_use_http) {
78 // Set attachment which is wired to network directly instead of
79 // being serialized into protobuf messages.
80 cntl->response_attachment().append(cntl->request_attachment());
81 }
82 }
83};
84} // namespace example
85

Callers 1

senderFunction · 0.45

Calls 9

set_timeout_msMethod · 0.80
set_max_retryMethod · 0.80
ErrorTextMethod · 0.80
ErrorCodeMethod · 0.80
messageMethod · 0.45
FailedMethod · 0.45
SetFailedMethod · 0.45
c_strMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected