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

Function main

example/partition_echo_c++/client.cpp:124–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122
123
124int main(int argc, char* argv[]) {
125 // Parse gflags. We recommend you to use gflags as well.
126 GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
127
128 // A Channel represents a communication line to a Server. Notice that
129 // Channel is thread-safe and can be shared by all threads in your program.
130 brpc::PartitionChannel channel;
131
132 brpc::PartitionChannelOptions options;
133 options.protocol = FLAGS_protocol;
134 options.connection_type = FLAGS_connection_type;
135 options.succeed_without_server = true;
136 options.fail_limit = 1;
137 options.timeout_ms = FLAGS_timeout_ms/*milliseconds*/;
138 options.max_retry = FLAGS_max_retry;
139
140 if (channel.Init(FLAGS_partition_num, new MyPartitionParser(),
141 FLAGS_server.c_str(),
142 FLAGS_load_balancer.c_str(),
143 &options) != 0) {
144 LOG(ERROR) << "Fail to init channel";
145 return -1;
146 }
147 if (FLAGS_attachment_size > 0) {
148 g_attachment.resize(FLAGS_attachment_size, 'a');
149 }
150 if (FLAGS_request_size <= 0) {
151 LOG(ERROR) << "Bad request_size=" << FLAGS_request_size;
152 return -1;
153 }
154 g_request.resize(FLAGS_request_size, 'r');
155
156 std::vector<bthread_t> bids;
157 std::vector<pthread_t> pids;
158 if (!FLAGS_use_bthread) {
159 pids.resize(FLAGS_thread_num);
160 for (int i = 0; i < FLAGS_thread_num; ++i) {
161 if (pthread_create(&pids[i], NULL, sender, &channel) != 0) {
162 LOG(ERROR) << "Fail to create pthread";
163 return -1;
164 }
165 }
166 } else {
167 bids.resize(FLAGS_thread_num);
168 for (int i = 0; i < FLAGS_thread_num; ++i) {
169 if (bthread_start_background(
170 &bids[i], NULL, sender, &channel) != 0) {
171 LOG(ERROR) << "Fail to create bthread";
172 return -1;
173 }
174 }
175 }
176
177 int64_t last_counter = 0;
178 int64_t last_latency_sum = 0;
179 std::vector<size_t> last_nsuccess(FLAGS_thread_num);
180 while (!brpc::IsAskedToQuit()) {
181 sleep(1);

Callers

nothing calls this directly

Calls 9

bthread_start_backgroundFunction · 0.85
IsAskedToQuitFunction · 0.85
pthread_mutex_lockFunction · 0.85
pthread_mutex_unlockFunction · 0.85
bthread_joinFunction · 0.85
InitMethod · 0.45
c_strMethod · 0.45
resizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected