| 39 | bvar::LatencyRecorder g_latency_recorder("client"); |
| 40 | |
| 41 | static 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 | |
| 75 | int main(int argc, char* argv[]) { |
| 76 | // Parse gflags. We recommend you to use gflags as well. |
nothing calls this directly
no test coverage detected