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

Function main

example/multi_threaded_echo_c++/client.cpp:86–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84}
85
86int main(int argc, char* argv[]) {
87 // Parse gflags. We recommend you to use gflags as well.
88 GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
89
90 // A Channel represents a communication line to a Server. Notice that
91 // Channel is thread-safe and can be shared by all threads in your program.
92 brpc::Channel channel;
93
94 // Initialize the channel, NULL means using default options.
95 brpc::ChannelOptions options;
96 if (FLAGS_enable_ssl) {
97 options.mutable_ssl_options();
98 }
99 options.protocol = FLAGS_protocol;
100 options.connection_type = FLAGS_connection_type;
101 options.connect_timeout_ms = std::min(FLAGS_timeout_ms / 2, 100);
102 options.timeout_ms = FLAGS_timeout_ms;
103 options.max_retry = FLAGS_max_retry;
104 if (channel.Init(FLAGS_server.c_str(), FLAGS_load_balancer.c_str(), &options) != 0) {
105 LOG(ERROR) << "Fail to initialize channel";
106 return -1;
107 }
108
109 if (FLAGS_attachment_size > 0) {
110 g_attachment.resize(FLAGS_attachment_size, 'a');
111 }
112 if (FLAGS_request_size <= 0) {
113 LOG(ERROR) << "Bad request_size=" << FLAGS_request_size;
114 return -1;
115 }
116 g_request.resize(FLAGS_request_size, 'r');
117
118 if (FLAGS_dummy_port >= 0) {
119 brpc::StartDummyServerAt(FLAGS_dummy_port);
120 }
121
122 std::vector<bthread_t> bids;
123 std::vector<pthread_t> pids;
124 if (!FLAGS_use_bthread) {
125 pids.resize(FLAGS_thread_num);
126 for (int i = 0; i < FLAGS_thread_num; ++i) {
127 if (pthread_create(&pids[i], NULL, sender, &channel) != 0) {
128 LOG(ERROR) << "Fail to create pthread";
129 return -1;
130 }
131 }
132 } else {
133 bids.resize(FLAGS_thread_num);
134 for (int i = 0; i < FLAGS_thread_num; ++i) {
135 if (bthread_start_background(
136 &bids[i], NULL, sender, &channel) != 0) {
137 LOG(ERROR) << "Fail to create bthread";
138 return -1;
139 }
140 }
141 }
142
143 while (!brpc::IsAskedToQuit()) {

Callers

nothing calls this directly

Calls 10

StartDummyServerAtFunction · 0.85
bthread_start_backgroundFunction · 0.85
IsAskedToQuitFunction · 0.85
bthread_joinFunction · 0.85
latencyMethod · 0.80
mutable_ssl_optionsMethod · 0.45
InitMethod · 0.45
c_strMethod · 0.45
resizeMethod · 0.45
qpsMethod · 0.45

Tested by

no test coverage detected