wwbmmm commented on code in PR #1818:
URL: https://github.com/apache/incubator-brpc/pull/1818#discussion_r904477754


##########
src/butil/endpoint.cpp:
##########
@@ -193,12 +195,33 @@ int hostname2ip(const char* hostname, ip_t* ip) {
         return -1;
     }
 #else
-    char aux_buf[1024];
+    int aux_buf_len = 1024;
+    std::unique_ptr<char[]> aux_buf(new char[aux_buf_len]);
+    int ret = 0;
     int error = 0;
     struct hostent ent;
     struct hostent* result = NULL;
-    if (gethostbyname_r(hostname, &ent, aux_buf, sizeof(aux_buf),
-                        &result, &error) != 0 || result == NULL) {
+    do {
+        result = NULL;
+        error = 0;
+        ret = gethostbyname_r(hostname, &ent, aux_buf.get(), aux_buf_len,
+            &result, &error);
+        if (ret != ERANGE) { // aux_buf is not long enough
+            break;
+        }
+        aux_buf_len *= 2;
+        aux_buf.reset(new char[aux_buf_len]);
+        RPC_VLOG << "Resized aux_buf to " << aux_buf_len
+                 << ", hostname=" << hostname;
+    } while (1);
+    if (ret != 0) {
+        // `hstrerror' is thread safe under linux
+        LOG(WARNING) << "Can't resolve `" << hostname << "', return=`" << 
berror(ret)

Review Comment:
   这个函数比较底层,可能不适合打WARNING,因为有些场景解析不到是符合预期的。



##########
src/butil/endpoint.cpp:
##########
@@ -32,7 +32,9 @@
 #include "butil/logging.h"
 #include "butil/memory/singleton_on_pthread_once.h"
 #include "butil/strings/string_piece.h"
+#include "brpc/log.h"

Review Comment:
   butil反过来依赖brpc目录的文件不太合适



-- 
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-unsubscr...@brpc.apache.org

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


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

Reply via email to