| 70 | }; |
| 71 | |
| 72 | int ChannelGroup::Init() { |
| 73 | { |
| 74 | // force global initialization of rpc. |
| 75 | brpc::Channel dummy_channel; |
| 76 | } |
| 77 | std::vector<std::pair<brpc::ProtocolType, brpc::Protocol> > protocols; |
| 78 | brpc::ListProtocols(&protocols); |
| 79 | size_t max_protocol_size = 0; |
| 80 | for (size_t i = 0; i < protocols.size(); ++i) { |
| 81 | max_protocol_size = std::max(max_protocol_size, |
| 82 | (size_t)protocols[i].first); |
| 83 | } |
| 84 | _chans.resize(max_protocol_size + 1); |
| 85 | for (size_t i = 0; i < protocols.size(); ++i) { |
| 86 | const brpc::ProtocolType protocol_type = protocols[i].first; |
| 87 | const brpc::Protocol protocol = protocols[i].second; |
| 88 | brpc::ChannelOptions options; |
| 89 | options.protocol = protocol_type; |
| 90 | options.connection_type = FLAGS_connection_type; |
| 91 | options.timeout_ms = FLAGS_timeout_ms/*milliseconds*/; |
| 92 | options.max_retry = FLAGS_max_retry; |
| 93 | if ((options.connection_type == brpc::CONNECTION_TYPE_UNKNOWN || |
| 94 | options.connection_type & protocol.supported_connection_type) && |
| 95 | protocol.support_client() && |
| 96 | protocol.support_server()) { |
| 97 | brpc::Channel* chan = new brpc::Channel; |
| 98 | if (chan->Init(FLAGS_server.c_str(), FLAGS_load_balancer.c_str(), |
| 99 | &options) != 0) { |
| 100 | LOG(ERROR) << "Fail to initialize channel"; |
| 101 | delete chan; |
| 102 | return -1; |
| 103 | } |
| 104 | _chans[protocol_type] = chan; |
| 105 | } |
| 106 | } |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | ChannelGroup::~ChannelGroup() { |
| 111 | for (size_t i = 0; i < _chans.size(); ++i) { |
no test coverage detected