| 84 | } |
| 85 | |
| 86 | int 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 | options.protocol = FLAGS_protocol; |
| 97 | options.connection_type = FLAGS_connection_type; |
| 98 | options.timeout_ms = FLAGS_timeout_ms/*milliseconds*/; |
| 99 | options.max_retry = FLAGS_max_retry; |
| 100 | if (channel.Init(FLAGS_server.c_str(), FLAGS_load_balancer.c_str(), &options) != 0) { |
| 101 | LOG(ERROR) << "Fail to initialize channel"; |
| 102 | return -1; |
| 103 | } |
| 104 | |
| 105 | if (FLAGS_attachment_size > 0) { |
| 106 | g_attachment.resize(FLAGS_attachment_size, 'a'); |
| 107 | } |
| 108 | if (FLAGS_request_size <= 0) { |
| 109 | LOG(ERROR) << "Bad request_size=" << FLAGS_request_size; |
| 110 | return -1; |
| 111 | } |
| 112 | g_request.resize(FLAGS_request_size, 'r'); |
| 113 | |
| 114 | std::vector<bthread_t> bids; |
| 115 | std::vector<pthread_t> pids; |
| 116 | if (!FLAGS_use_bthread) { |
| 117 | pids.resize(FLAGS_thread_num); |
| 118 | for (int i = 0; i < FLAGS_thread_num; ++i) { |
| 119 | if (pthread_create(&pids[i], NULL, sender, &channel) != 0) { |
| 120 | LOG(ERROR) << "Fail to create pthread"; |
| 121 | return -1; |
| 122 | } |
| 123 | } |
| 124 | } else { |
| 125 | bids.resize(FLAGS_thread_num); |
| 126 | for (int i = 0; i < FLAGS_thread_num; ++i) { |
| 127 | if (bthread_start_background( |
| 128 | &bids[i], NULL, sender, &channel) != 0) { |
| 129 | LOG(ERROR) << "Fail to create bthread"; |
| 130 | return -1; |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | while (!brpc::IsAskedToQuit()) { |
| 136 | sleep(1); |
| 137 | LOG(INFO) << "Sending EchoRequest at qps=" << g_latency_recorder.qps(1) |
| 138 | << " latency=" << g_latency_recorder.latency(1); |
| 139 | } |
| 140 | |
| 141 | LOG(INFO) << "EchoClient is going to quit"; |
| 142 | for (int i = 0; i < FLAGS_thread_num; ++i) { |
| 143 | if (!FLAGS_use_bthread) { |
nothing calls this directly
no test coverage detected