本文整理汇总了C++中NetworkInterface::gethostbyname_async方法的典型用法代码示例。如果您正苦于以下问题:C++ NetworkInterface::gethostbyname_async方法的具体用法?C++ NetworkInterface::gethostbyname_async怎么用?C++ NetworkInterface::gethostbyname_async使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkInterface
的用法示例。
在下文中一共展示了NetworkInterface::gethostbyname_async方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MULTIHOMING_ASYNCHRONOUS_DNS
void MULTIHOMING_ASYNCHRONOUS_DNS()
{
rtos::Semaphore semaphore;
dns_application_data data;
data.semaphore = &semaphore;
for (unsigned int i = 0; i < MBED_CONF_APP_DNS_TEST_HOSTS_NUM; i++) {
for (unsigned int interface_index = 0; interface_index < MBED_CONF_MULTIHOMING_MAX_INTERFACES_NUM; interface_index++) {
NetworkInterface *interface = get_interface(interface_index);
if (interface == NULL) {
continue;
}
for (unsigned int j = 0; j < interface_num; j++) {
nsapi_error_t err = interface->gethostbyname_async(dns_test_hosts[i],
mbed::Callback<void(nsapi_error_t, SocketAddress *)>(hostbyname_cb, (void *) &data), NSAPI_UNSPEC, interface_name[j]);
TEST_ASSERT(err >= 0);
semaphore.wait();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, data.result);
printf("DNS: query interface_name %s %d \n", interface_name[j], j);
if (data.result == NSAPI_ERROR_OK) {
result_ok++;
printf("DNS: query OK \"%s\" => \"%s\"\n", dns_test_hosts[i], data.addr.get_ip_address());
} else if (data.result == NSAPI_ERROR_DNS_FAILURE) {
result_dns_failure++;
printf("DNS: query \"%s\" => DNS failure\n", dns_test_hosts[i]);
} else if (data.result == NSAPI_ERROR_TIMEOUT) {
result_exp_timeout++;
printf("DNS: query \"%s\" => timeout\n", dns_test_hosts[i]);
} else if (data.result == NSAPI_ERROR_NO_MEMORY) {
result_no_mem++;
printf("DNS: query \"%s\" => no memory\n", dns_test_hosts[i]);
} else {
printf("DNS: query \"%s\" => %d, unexpected answer\n", dns_test_hosts[i], data.result);
TEST_ASSERT(data.result == NSAPI_ERROR_OK || data.result == NSAPI_ERROR_NO_MEMORY || data.result == NSAPI_ERROR_DNS_FAILURE || data.result == NSAPI_ERROR_TIMEOUT);
}
}
}
}
}