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

Function sender

example/thrift_extension_c++/client2.cpp:46–78  ·  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 brpc::ThriftStub stub(static_cast<brpc::Channel*>(arg));
50
51 while (!brpc::IsAskedToQuit()) {
52 // We will receive response synchronously, safe to put variables
53 // on stack.
54 example::EchoRequest req;
55 example::EchoResponse res;
56 brpc::Controller cntl;
57
58 req.__set_data(g_request);
59 req.__set_need_by_proxy(10);
60
61 // Because `done'(last parameter) is NULL, this function waits until
62 // the response comes back or error occurs(including timedout).
63 stub.CallMethod("Echo", &cntl, &req, &res, NULL);
64 if (!cntl.Failed()) {
65 g_latency_recorder << cntl.latency_us();
66 } else {
67 g_error_count << 1;
68 CHECK(brpc::IsAskedToQuit() || !FLAGS_dont_fail)
69 << "error=" << cntl.ErrorText() << " latency=" << cntl.latency_us();
70 // We can't connect to the server, sleep a while. Notice that this
71 // is a specific sleeping to prevent this thread from spinning too
72 // fast. You should continue the business logic in a production
73 // server rather than sleeping.
74 bthread_usleep(50000);
75 }
76 }
77 return NULL;
78}
79
80int main(int argc, char* argv[]) {
81 // Parse gflags. We recommend you to use gflags as well.

Callers

nothing calls this directly

Calls 6

IsAskedToQuitFunction · 0.85
bthread_usleepFunction · 0.85
latency_usMethod · 0.80
ErrorTextMethod · 0.80
CallMethodMethod · 0.45
FailedMethod · 0.45

Tested by

no test coverage detected