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

Function sender

example/cascade_echo_c++/client.cpp:47–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45bvar::LatencyRecorder g_latency_recorder("client");
46
47void* sender(void* arg) {
48 brpc::Channel* chan = (brpc::Channel*)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(chan);
52
53 // Send a request and wait for the response every 1 second.
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("hello world");
62 if (FLAGS_depth > 0) {
63 request.set_depth(FLAGS_depth);
64 }
65
66 // Set request_id to be a random string
67 cntl.set_request_id(butil::fast_rand_printable(9));
68
69 // Set attachment which is wired to network directly instead of
70 // being serialized into protobuf messages.
71 cntl.request_attachment().append(FLAGS_attachment);
72
73 // Because `done'(last parameter) is NULL, this function waits until
74 // the response comes back or error occurs(including timedout).
75 stub.Echo(&cntl, &request, &response, NULL);
76 if (cntl.Failed()) {
77 //LOG_EVERY_SECOND(WARNING) << "Fail to send EchoRequest, " << cntl.ErrorText();
78 } else {
79 g_latency_recorder << cntl.latency_us();
80 }
81 if (FLAGS_sleep_ms != 0) {
82 bthread_usleep(FLAGS_sleep_ms * 1000L);
83 }
84 }
85 return NULL;
86}
87
88int main(int argc, char* argv[]) {
89 // Parse gflags. We recommend you to use gflags as well.

Callers

nothing calls this directly

Calls 8

IsAskedToQuitFunction · 0.85
fast_rand_printableFunction · 0.85
bthread_usleepFunction · 0.85
set_request_idMethod · 0.80
latency_usMethod · 0.80
appendMethod · 0.45
EchoMethod · 0.45
FailedMethod · 0.45

Tested by

no test coverage detected