| 248 | } |
| 249 | |
| 250 | int Channel::Init(const char* server_addr_and_port, |
| 251 | const ChannelOptions* options) { |
| 252 | GlobalInitializeOrDie(); |
| 253 | butil::EndPoint point; |
| 254 | const AdaptiveProtocolType& ptype = (options ? options->protocol : _options.protocol); |
| 255 | const Protocol* protocol = FindProtocol(ptype); |
| 256 | if (protocol == NULL || !protocol->support_client()) { |
| 257 | LOG(ERROR) << "Channel does not support the protocol"; |
| 258 | return -1; |
| 259 | } |
| 260 | if (protocol->parse_server_address != NULL) { |
| 261 | if (!protocol->parse_server_address(&point, server_addr_and_port)) { |
| 262 | LOG(ERROR) << "Fail to parse address=`" << server_addr_and_port << '\''; |
| 263 | return -1; |
| 264 | } |
| 265 | } else { |
| 266 | if (str2endpoint(server_addr_and_port, &point) != 0 && |
| 267 | hostname2endpoint(server_addr_and_port, &point) != 0) { |
| 268 | // Many users called the wrong Init(). Print some log to save |
| 269 | // our troubleshooting time. |
| 270 | if (strstr(server_addr_and_port, "://")) { |
| 271 | LOG(ERROR) << "Invalid address=`" << server_addr_and_port |
| 272 | << "'. Use Init(naming_service_name, " |
| 273 | "load_balancer_name, options) instead."; |
| 274 | } else { |
| 275 | LOG(ERROR) << "Invalid address=`" << server_addr_and_port << '\''; |
| 276 | } |
| 277 | return -1; |
| 278 | } |
| 279 | } |
| 280 | return InitSingle(point, server_addr_and_port, options); |
| 281 | } |
| 282 | |
| 283 | int Channel::Init(const char* server_addr, int port, |
| 284 | const ChannelOptions* options) { |
nothing calls this directly
no test coverage detected