| 44 | bvar::Adder<int> g_error_count("client_error_count"); |
| 45 | |
| 46 | static 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 | |
| 80 | int main(int argc, char* argv[]) { |
| 81 | // Parse gflags. We recommend you to use gflags as well. |
nothing calls this directly
no test coverage detected