zyearn commented on a change in pull request #1529:
URL: https://github.com/apache/incubator-brpc/pull/1529#discussion_r696942243
##########
File path: src/brpc/channel.cpp
##########
@@ -243,6 +252,15 @@ int Channel::Init(const char* server_addr, int port,
LOG(ERROR) << "Channel does not support the protocol";
return -1;
}
+ if (ptype == brpc::PROTOCOL_HTTP) {
+ std::string host;
+ if (ParseURL(server_addr, NULL, &host, NULL) == 0) {
+ butil::ip_t ip;
+ if (butil::hostname2ip(host.c_str(), &ip) == 0) {
+ _hostname.swap(host);
+ }
+ }
+ }
Review comment:
1. 这段可以直接写在InitSingle里吗?这样就不用重复写在两个Init里了
2. 另外这段可以封装成函数,因为在single和集群同时用到了
3. 感觉可以不用判断协议,对所有协议而言把这个hostname存下来没什么坏处,以后拓展协议用到的话,也更容易。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]