| 46 | bvar::Adder<int> g_error_count("client_error_count"); |
| 47 | |
| 48 | static void* sender(void* arg) { |
| 49 | // Normally, you should not call a Channel directly, but instead construct |
| 50 | // a stub Service wrapping it. stub can be shared by all threads as well. |
| 51 | example::EchoService_Stub stub(static_cast<google::protobuf::RpcChannel*>(arg)); |
| 52 | |
| 53 | int log_id = 0; |
| 54 | while (!brpc::IsAskedToQuit()) { |
| 55 | // We will receive response synchronously, safe to put variables |
| 56 | // on stack. |
| 57 | example::EchoRequest request; |
| 58 | example::EchoResponse response; |
| 59 | brpc::Controller cntl; |
| 60 | |
| 61 | request.set_message(g_request); |
| 62 | cntl.set_log_id(log_id++); // set by user |
| 63 | // Set attachment which is wired to network directly instead of |
| 64 | // being serialized into protobuf messages. |
| 65 | cntl.request_attachment().append(g_attachment); |
| 66 | |
| 67 | // Because `done'(last parameter) is NULL, this function waits until |
| 68 | // the response comes back or error occurs(including timedout). |
| 69 | stub.Echo(&cntl, &request, &response, NULL); |
| 70 | if (!cntl.Failed()) { |
| 71 | g_latency_recorder << cntl.latency_us(); |
| 72 | } else { |
| 73 | g_error_count << 1; |
| 74 | CHECK(brpc::IsAskedToQuit() || !FLAGS_dont_fail) |
| 75 | << "error=" << cntl.ErrorText() << " latency=" << cntl.latency_us(); |
| 76 | // We can't connect to the server, sleep a while. Notice that this |
| 77 | // is a specific sleeping to prevent this thread from spinning too |
| 78 | // fast. You should continue the business logic in a production |
| 79 | // server rather than sleeping. |
| 80 | bthread_usleep(50000); |
| 81 | } |
| 82 | } |
| 83 | return NULL; |
| 84 | } |
| 85 | |
| 86 | int main(int argc, char* argv[]) { |
| 87 | // Parse gflags. We recommend you to use gflags as well. |
nothing calls this directly
no test coverage detected