当前位置: 首页>>代码示例>>C++>>正文


C++ NetworkInterface::gethostbyname_async方法代码示例

本文整理汇总了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);
                }

            }
        }



    }
}
开发者ID:0xc0170,项目名称:mbed,代码行数:50,代码来源:multihoming_asynchronous_dns.cpp


注:本文中的NetworkInterface::gethostbyname_async方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。