Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: remove unused GetHostByNameWrap #17860

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 9 additions & 51 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>()) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1772,33 +1757,6 @@ class GetHostByAddrWrap: public QueryWrap {
};


class GetHostByNameWrap: public QueryWrap {
public:
explicit GetHostByNameWrap(ChannelWrap* channel, Local<Object> req_wrap_obj)
: QueryWrap(channel, req_wrap_obj) {
}

int Send(const char* name, int family) override {
ares_gethostbyname(channel_->cares_channel(),
name,
family,
Callback,
static_cast<void*>(static_cast<QueryWrap*>(this)));
return 0;
}

protected:
void Parse(struct hostent* host) override {
HandleScope scope(env()->isolate());

Local<Array> addresses = HostentToAddresses(env(), host);
Local<Integer> family = Integer::New(env()->isolate(), host->h_addrtype);

this->CallOnComplete(addresses, family);
}
};


template <class Wrap>
static void Query(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
Expand Down