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

Function sender

example/selective_echo_c++/client.cpp:46–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44bvar::Adder<int> g_error_count("client_error_count");
45
46static void* sender(void* arg) {
47 // Normally, you should not call a Channel directly, but instead construct
48 // a stub Service wrapping it. stub can be shared by all threads as well.
49 example::EchoService_Stub stub(static_cast<google::protobuf::RpcChannel*>(arg));
50
51 int log_id = 0;
52 while (!brpc::IsAskedToQuit()) {
53 // We will receive response synchronously, safe to put variables
54 // on stack.
55 example::EchoRequest request;
56 example::EchoResponse response;
57 brpc::Controller cntl;
58
59 request.set_message(g_request);
60 cntl.set_log_id(log_id++); // set by user
61
62 if (!g_attachment.empty()) {
63 // Set attachment which is wired to network directly instead of
64 // being serialized into protobuf messages.
65 cntl.request_attachment().append(g_attachment);
66 }
67
68 // Because `done'(last parameter) is NULL, this function waits until
69 // the response comes back or error occurs(including timedout).
70 stub.Echo(&cntl, &request, &response, NULL);
71 const int64_t elp = cntl.latency_us();
72 if (!cntl.Failed()) {
73 g_latency_recorder << cntl.latency_us();
74 } else {
75 g_error_count << 1;
76 CHECK(brpc::IsAskedToQuit() || !FLAGS_dont_fail)
77 << "error=" << cntl.ErrorText() << " latency=" << elp;
78 // We can't connect to the server, sleep a while. Notice that this
79 // is a specific sleeping to prevent this thread from spinning too // fast. You should continue the business logic in a production
80 // server rather than sleeping.
81 bthread_usleep(50000);
82 }
83 }
84 return NULL;
85}
86
87int main(int argc, char* argv[]) {
88 // Parse gflags. We recommend you to use gflags as well.

Callers

nothing calls this directly

Calls 9

IsAskedToQuitFunction · 0.85
bthread_usleepFunction · 0.85
latency_usMethod · 0.80
ErrorTextMethod · 0.80
set_log_idMethod · 0.45
emptyMethod · 0.45
appendMethod · 0.45
EchoMethod · 0.45
FailedMethod · 0.45

Tested by

no test coverage detected