| 46 | BTHREAD_STACKTYPE_NORMAL, BTHREAD_INHERIT_SPAN, NULL, BTHREAD_TAG_INVALID}; |
| 47 | |
| 48 | void* RunThreadFunc(void*) { |
| 49 | TRACEPRINTF("RunThreadFunc %lu", bthread_self()); |
| 50 | // brpc::FLAGS_enable_rpcz = true; |
| 51 | // A Channel represents a communication line to a Server. Notice that |
| 52 | // Channel is thread-safe and can be shared by all threads in your program. |
| 53 | brpc::Channel channel; |
| 54 | // Initialize the channel, NULL means using default options. |
| 55 | brpc::ChannelOptions options; |
| 56 | options.protocol = FLAGS_protocol; |
| 57 | options.connection_type = FLAGS_connection_type; |
| 58 | options.timeout_ms = FLAGS_timeout_ms /*milliseconds*/; |
| 59 | options.max_retry = FLAGS_max_retry; |
| 60 | if (channel.Init(FLAGS_server.c_str(), "", &options) != 0) { |
| 61 | LOG(ERROR) << "Fail to initialize channel"; |
| 62 | return nullptr; |
| 63 | } |
| 64 | example::EchoService_Stub stub(&channel); |
| 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 | request.set_message("hello world"); |
| 71 | |
| 72 | // Because `done'(last parameter) is NULL, this function waits until |
| 73 | // the response comes back or error occurs(including timedout). |
| 74 | stub.Echo(&cntl, &request, &response, NULL); |
| 75 | if (!cntl.Failed()) { |
| 76 | LOG(INFO) << "Received response from " << cntl.remote_side() << " to " << cntl.local_side() |
| 77 | << ": " << response.message() << " (attached=" << cntl.response_attachment() |
| 78 | << ")" |
| 79 | << " latency=" << cntl.latency_us() << "us"; |
| 80 | } else { |
| 81 | LOG(WARNING) << cntl.ErrorText(); |
| 82 | } |
| 83 | |
| 84 | return nullptr; |
| 85 | } |
| 86 | |
| 87 | class EchoServiceImpl : public EchoService { |
| 88 | public: |
nothing calls this directly
no test coverage detected