Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Unified Diff: native_client_sdk/src/libraries/nacl_io/host_resolver.cc

Issue 148223005: [NaCl SDK] Add fake for ppb_host_resolver and ppb_net_address (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | native_client_sdk/src/libraries/nacl_io/kernel_intercept.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: native_client_sdk/src/libraries/nacl_io/host_resolver.cc
diff --git a/native_client_sdk/src/libraries/nacl_io/host_resolver.cc b/native_client_sdk/src/libraries/nacl_io/host_resolver.cc
index beae7261b50ff531bad9224f2326bbf183607d1a..394070550e0fa402bda9c539058af2dfad776600 100644
--- a/native_client_sdk/src/libraries/nacl_io/host_resolver.cc
+++ b/native_client_sdk/src/libraries/nacl_io/host_resolver.cc
@@ -33,7 +33,15 @@ struct hostent* HostResolver::gethostbyname(const char* name) {
return NULL;
HostResolverInterface* resolver_interface =
- ppapi_->GetHostResolverInterface();
+ ppapi_->GetHostResolverInterface();
+ VarInterface* var_interface = ppapi_->GetVarInterface();
+ NetAddressInterface* netaddr_iface = ppapi_->GetNetAddressInterface();
+
+ if (NULL == resolver_interface ||
+ NULL == netaddr_iface ||
+ NULL == var_interface)
+ return NULL;
+
ScopedResource resolver(ppapi_,
resolver_interface->Create(ppapi_->GetInstance()));
@@ -72,7 +80,7 @@ struct hostent* HostResolver::gethostbyname(const char* name) {
return NULL;
uint32_t len;
- const char* name_ptr = ppapi_->GetVarInterface()->VarToUtf8(name_var, &len);
+ const char* name_ptr = var_interface->VarToUtf8(name_var, &len);
if (NULL == name_ptr)
return NULL;
if (0 == len) {
@@ -88,19 +96,20 @@ struct hostent* HostResolver::gethostbyname(const char* name) {
memcpy(hostent_.h_name, name_ptr, len);
hostent_.h_name[len] = '\0';
+ var_interface->Release(name_var);
+
// Aliases aren't supported at the moment, so we just make an empty list.
hostent_.h_aliases = static_cast<char**>(malloc(sizeof(char*)));
if (NULL == hostent_.h_aliases)
return NULL;
hostent_.h_aliases[0] = NULL;
- NetAddressInterface* netaddr_interface = ppapi_->GetNetAddressInterface();
- PP_Resource addr =
- resolver_interface->GetNetAddress(resolver.pp_resource(), 0);
- if (!PP_ToBool(netaddr_interface->IsNetAddress(addr)))
+ ScopedResource addr(ppapi_);
+ addr.Reset(resolver_interface->GetNetAddress(resolver.pp_resource(), 0));
+ if (!PP_ToBool(netaddr_iface->IsNetAddress(addr.pp_resource())))
return NULL;
- switch (netaddr_interface->GetFamily(addr)) {
+ switch (netaddr_iface->GetFamily(addr.pp_resource())) {
case PP_NETADDRESS_FAMILY_IPV4:
hostent_.h_addrtype = AF_INET;
hostent_.h_length = 4;
@@ -123,22 +132,20 @@ struct hostent* HostResolver::gethostbyname(const char* name) {
return NULL;
for (uint32_t i = 0; i < num_addresses; i++) {
- PP_Resource addr =
- resolver_interface->GetNetAddress(resolver.pp_resource(), i);
- if (!PP_ToBool(netaddr_interface->IsNetAddress(addr)))
+ addr.Reset(resolver_interface->GetNetAddress(resolver.pp_resource(), i));
+ if (!PP_ToBool(netaddr_iface->IsNetAddress(addr.pp_resource())))
return NULL;
if (AF_INET == hostent_.h_addrtype) {
struct PP_NetAddress_IPv4 addr_struct;
- if (!netaddr_interface->DescribeAsIPv4Address(addr, &addr_struct)) {
+ if (!netaddr_iface->DescribeAsIPv4Address(addr.pp_resource(), &addr_struct))
return NULL;
- }
hostent_.h_addr_list[i] = static_cast<char*>(malloc(hostent_.h_length));
if (NULL == hostent_.h_addr_list[i])
return NULL;
memcpy(hostent_.h_addr_list[i], addr_struct.addr, hostent_.h_length);
} else { // IPv6
struct PP_NetAddress_IPv6 addr_struct;
- if (!netaddr_interface->DescribeAsIPv6Address(addr, &addr_struct))
+ if (!netaddr_iface->DescribeAsIPv6Address(addr.pp_resource(), &addr_struct))
return NULL;
hostent_.h_addr_list[i] = static_cast<char*>(malloc(hostent_.h_length));
if (NULL == hostent_.h_addr_list[i])
« no previous file with comments | « no previous file | native_client_sdk/src/libraries/nacl_io/kernel_intercept.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698