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

Function sender

example/http_c++/benchmark_http.cpp:41–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39bvar::LatencyRecorder g_latency_recorder("client");
40
41static void* sender(void* arg) {
42 brpc::Channel* channel = static_cast<brpc::Channel*>(arg);
43
44 while (!brpc::IsAskedToQuit()) {
45 // We will receive response synchronously, safe to put variables
46 // on stack.
47 brpc::Controller cntl;
48
49 cntl.set_timeout_ms(FLAGS_timeout_ms/*milliseconds*/);
50 cntl.set_max_retry(FLAGS_max_retry);
51 cntl.http_request().uri() = FLAGS_url;
52 if (!FLAGS_data.empty()) {
53 cntl.http_request().set_method(brpc::HTTP_METHOD_POST);
54 cntl.request_attachment().append(FLAGS_data);
55 }
56
57 // Because `done'(last parameter) is NULL, this function waits until
58 // the response comes back or error occurs(including timedout).
59 channel->CallMethod(NULL, &cntl, NULL, NULL, NULL);
60 if (!cntl.Failed()) {
61 g_latency_recorder << cntl.latency_us();
62 } else {
63 CHECK(brpc::IsAskedToQuit() || !FLAGS_dont_fail)
64 << "error=" << cntl.ErrorText() << " latency=" << cntl.latency_us();
65 // We can't connect to the server, sleep a while. Notice that this
66 // is a specific sleeping to prevent this thread from spinning too
67 // fast. You should continue the business logic in a production
68 // server rather than sleeping.
69 bthread_usleep(100000);
70 }
71 }
72 return NULL;
73}
74
75int main(int argc, char* argv[]) {
76 // Parse gflags. We recommend you to use gflags as well.

Callers

nothing calls this directly

Calls 11

IsAskedToQuitFunction · 0.85
bthread_usleepFunction · 0.85
set_timeout_msMethod · 0.80
set_max_retryMethod · 0.80
latency_usMethod · 0.80
ErrorTextMethod · 0.80
emptyMethod · 0.45
set_methodMethod · 0.45
appendMethod · 0.45
CallMethodMethod · 0.45
FailedMethod · 0.45

Tested by

no test coverage detected