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

Function sender

example/partition_echo_c++/client.cpp:52–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected