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

Method Echo

example/asynchronous_echo_c++/server.cpp:36–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.45

Calls 5

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

Tested by

no test coverage detected