empiredan commented on code in PR #1869:
URL: 
https://github.com/apache/incubator-pegasus/pull/1869#discussion_r1470606496


##########
src/runtime/rpc/rpc_address.cpp:
##########
@@ -27,44 +27,64 @@
 #include "runtime/rpc/rpc_address.h"
 
 #include <arpa/inet.h>
+#include <errno.h>
 #include <ifaddrs.h>
 #include <netdb.h>
 #include <netinet/in.h>
 #include <string.h>
 #include <sys/socket.h>
 
+#include "absl/strings/string_view.h"
 #include "runtime/rpc/group_address.h"
+#include "utils/error_code.h"
 #include "utils/fixed_size_buffer_pool.h"
 #include "utils/fmt_logging.h"
 #include "utils/ports.h"
+#include "utils/safe_strerror_posix.h"
 #include "utils/string_conv.h"
-#include "absl/strings/string_view.h"
 #include "utils/strings.h"
 
 namespace dsn {
+/*static*/
+error_s rpc_address::GetAddrInfo(const std::string &hostname, const addrinfo 
&hints, AddrInfo *info)
+{
+    addrinfo *res = nullptr;
+    const int rc = getaddrinfo(hostname.c_str(), nullptr, &hints, &res);
+    const int err = errno; // preserving the errno from the getaddrinfo() call
+    AddrInfo result(res, ::freeaddrinfo);
+    if (rc != 0) {

Review Comment:
   ```suggestion
       if (dsn_unlikely(rc != 0)) {
   ```



##########
src/runtime/rpc/rpc_address.cpp:
##########
@@ -27,44 +27,64 @@
 #include "runtime/rpc/rpc_address.h"
 
 #include <arpa/inet.h>
+#include <errno.h>
 #include <ifaddrs.h>
 #include <netdb.h>
 #include <netinet/in.h>
 #include <string.h>
 #include <sys/socket.h>
 
+#include "absl/strings/string_view.h"
 #include "runtime/rpc/group_address.h"
+#include "utils/error_code.h"
 #include "utils/fixed_size_buffer_pool.h"
 #include "utils/fmt_logging.h"
 #include "utils/ports.h"
+#include "utils/safe_strerror_posix.h"
 #include "utils/string_conv.h"
-#include "absl/strings/string_view.h"
 #include "utils/strings.h"
 
 namespace dsn {
+/*static*/
+error_s rpc_address::GetAddrInfo(const std::string &hostname, const addrinfo 
&hints, AddrInfo *info)
+{
+    addrinfo *res = nullptr;
+    const int rc = getaddrinfo(hostname.c_str(), nullptr, &hints, &res);
+    const int err = errno; // preserving the errno from the getaddrinfo() call
+    AddrInfo result(res, ::freeaddrinfo);
+    if (rc != 0) {
+        if (rc == EAI_SYSTEM) {
+            LOG_ERROR(
+                "getaddrinfo failed, name = {}, err = {}", hostname, 
utils::safe_strerror(rc));
+            return error_s::make(ERR_NETWORK_FAILURE, 
utils::safe_strerror(err));

Review Comment:
   ```suggestion
               const auto &err_msg = utils::safe_strerror(err);
               LOG_ERROR(
                   "getaddrinfo failed, name = {}, err = {}", hostname, 
err_msg);
               return error_s::make(ERR_NETWORK_FAILURE, err_msg);
   ```



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

Reply via email to