acelyc111 commented on code in PR #1869:
URL:
https://github.com/apache/incubator-pegasus/pull/1869#discussion_r1466245741
##########
src/runtime/rpc/rpc_address.cpp:
##########
@@ -48,23 +50,27 @@ const rpc_address rpc_address::s_invalid_address;
/*static*/
uint32_t rpc_address::ipv4_from_host(const char *name)
{
- sockaddr_in addr;
- memset(&addr, 0, sizeof(addr));
-
- addr.sin_family = AF_INET;
- if ((addr.sin_addr.s_addr = inet_addr(name)) == (unsigned int)(-1)) {
- // TODO(yingchun): use getaddrinfo instead
- hostent *hp = ::gethostbyname(name);
- if (dsn_unlikely(hp == nullptr)) {
- LOG_ERROR("gethostbyname failed, name = {}, err = {}", name,
hstrerror(h_errno));
- return 0;
- }
+ struct addrinfo hints;
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_INET;
+ hints.ai_socktype = SOCK_STREAM;
+ addrinfo *res = nullptr;
- memcpy((void *)&(addr.sin_addr.s_addr), (const void *)hp->h_addr,
(size_t)hp->h_length);
+ const int rc = getaddrinfo(name, nullptr, &hints, &res);
Review Comment:
Use dsn::defer() to release it automatically to prevent forgetting it.
--
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]