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