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

Function sender

example/parallel_echo_c++/client.cpp:51–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 11

IsAskedToQuitFunction · 0.85
bthread_usleepFunction · 0.85
latency_usMethod · 0.80
sub_countMethod · 0.80
subMethod · 0.80
ErrorTextMethod · 0.80
set_valueMethod · 0.45
emptyMethod · 0.45
appendMethod · 0.45
EchoMethod · 0.45
FailedMethod · 0.45

Tested by

no test coverage detected