diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2017-12-25 10:48:33 +0300 |
---|---|---|
committer | Jon Moss <me@jonathanmoss.me> | 2018-01-04 05:27:50 +0300 |
commit | f89ee0634a13bdb3f552385a76decdca6b13bdcf (patch) | |
tree | 2f2711e932a2f0c36593da048c577d775cd0e333 /src/cares_wrap.cc | |
parent | a0cc20eaba44292d6ad607109b32c541ff564933 (diff) |
src: inline HostentToAddresses()
With the removal of `GetHostByNameWrap` in the previous commit, there
is only one remaining call site. Inlining it there lets us simplify
the logic.
PR-URL: https://github.com/nodejs/node/pull/17860
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Diffstat (limited to 'src/cares_wrap.cc')
-rw-r--r-- | src/cares_wrap.cc | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index b9ab1b215e0..de3cb8f89c1 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -367,26 +367,6 @@ void ares_sockstate_cb(void* data, } -Local<Array> HostentToAddresses(Environment* env, - struct hostent* host, - Local<Array> append_to = Local<Array>()) { - EscapableHandleScope scope(env->isolate()); - auto context = env->context(); - bool append = !append_to.IsEmpty(); - Local<Array> addresses = append ? append_to : Array::New(env->isolate()); - size_t offset = addresses->Length(); - - char ip[INET6_ADDRSTRLEN]; - for (uint32_t i = 0; host->h_addr_list[i] != nullptr; ++i) { - uv_inet_ntop(host->h_addrtype, host->h_addr_list[i], ip, sizeof(ip)); - Local<String> address = OneByteString(env->isolate(), ip); - addresses->Set(context, i + offset, address).FromJust(); - } - - return append ? addresses : scope.Escape(addresses); -} - - Local<Array> HostentToNames(Environment* env, struct hostent* host, Local<Array> append_to = Local<Array>()) { @@ -843,12 +823,17 @@ int ParseGeneralReply(Environment* env, } else if (*type == ns_t_ptr) { uint32_t offset = ret->Length(); for (uint32_t i = 0; host->h_aliases[i] != nullptr; i++) { - ret->Set(context, - i + offset, - OneByteString(env->isolate(), host->h_aliases[i])).FromJust(); + auto alias = OneByteString(env->isolate(), host->h_aliases[i]); + ret->Set(context, i + offset, alias).FromJust(); } } else { - HostentToAddresses(env, host, ret); + uint32_t offset = ret->Length(); + char ip[INET6_ADDRSTRLEN]; + for (uint32_t i = 0; host->h_addr_list[i] != nullptr; ++i) { + uv_inet_ntop(host->h_addrtype, host->h_addr_list[i], ip, sizeof(ip)); + auto address = OneByteString(env->isolate(), ip); + ret->Set(context, i + offset, address).FromJust(); + } } ares_free_hostent(host); |