You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by GitBox <gi...@apache.org> on 2021/08/26 20:07:42 UTC

[GitHub] [incubator-brpc] zyearn commented on a change in pull request #1529: Set hostname rather than ip when channel Init by hostname but not host in http_requst().uri()

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: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org