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

Method Echo

example/cancel_c++/server.cpp:38–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.45

Calls 5

log_idMethod · 0.45
remote_sideMethod · 0.45
local_sideMethod · 0.45
messageMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected