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


##########
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:
   例如哪些场景呢?



-- 
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