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

Function RunThreadFunc

example/rpcz_echo_c++/server.cpp:48–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46 BTHREAD_STACKTYPE_NORMAL, BTHREAD_INHERIT_SPAN, NULL, BTHREAD_TAG_INVALID};
47
48void* 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
87class EchoServiceImpl : public EchoService {
88public:

Callers

nothing calls this directly

Calls 10

bthread_selfFunction · 0.85
latency_usMethod · 0.80
ErrorTextMethod · 0.80
InitMethod · 0.45
c_strMethod · 0.45
EchoMethod · 0.45
FailedMethod · 0.45
remote_sideMethod · 0.45
local_sideMethod · 0.45
messageMethod · 0.45

Tested by

no test coverage detected