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

Method Echo

example/echo_c++/server.cpp:42–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40 EchoServiceImpl() {}
41 virtual ~EchoServiceImpl() {}
42 virtual void Echo(google::protobuf::RpcController* cntl_base,
43 const EchoRequest* request,
44 EchoResponse* response,
45 google::protobuf::Closure* done) {
46 // This object helps you to call done->Run() in RAII style. If you need
47 // to process the request asynchronously, pass done_guard.release().
48 brpc::ClosureGuard done_guard(done);
49
50 brpc::Controller* cntl =
51 static_cast<brpc::Controller*>(cntl_base);
52
53 // optional: set a callback function which is called after response is sent
54 // and before cntl/req/res is destructed.
55 cntl->set_after_rpc_resp_fn(std::bind(&EchoServiceImpl::CallAfterRpc,
56 std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
57
58 // The purpose of following logs is to help you to understand
59 // how clients interact with servers more intuitively. You should
60 // remove these logs in performance-sensitive servers.
61 LOG(INFO) << "Received request[log_id=" << cntl->log_id()
62 << "] from " << cntl->remote_side()
63 << " to " << cntl->local_side()
64 << ": " << request->message()
65 << " (attached=" << cntl->request_attachment() << ")";
66
67 // Fill response.
68 response->set_message(request->message());
69
70 // You can compress the response by setting Controller, but be aware
71 // that compression may be costly, evaluate before turning on.
72 // cntl->set_response_compress_type(brpc::COMPRESS_TYPE_GZIP);
73
74 if (FLAGS_echo_attachment) {
75 // Set attachment which is wired to network directly instead of
76 // being serialized into protobuf messages.
77 cntl->response_attachment().append(cntl->request_attachment());
78 }
79
80 // Use checksum, only support CRC32C now.
81 if (FLAGS_enable_checksum) {
82 cntl->set_response_checksum_type(brpc::CHECKSUM_TYPE_CRC32C);
83 }
84 }
85
86 // optional
87 static void CallAfterRpc(brpc::Controller* cntl,

Callers 1

mainFunction · 0.45

Calls 7

set_after_rpc_resp_fnMethod · 0.80
log_idMethod · 0.45
remote_sideMethod · 0.45
local_sideMethod · 0.45
messageMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected