From d72076207a2fad96ff014a81366868fb47a0ed1b Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 31 Aug 2017 17:59:01 -0700 Subject: Allocate AIOs dynamically. We allocate AIO structures dynamically, so that we can use them abstractly in more places without inlining them. This will be used for the ZeroTier transport to allow us to create operations consisting of just the AIO. Furthermore, we provide accessors for some of the aio members, in the hopes that we will be able to wrap these for "safe" version of the AIO capability to export to applications, and to protocol and transport implementors. While here we cleaned up the protocol details to use consistently shorter names (no nni_ prefix for static symbols needed), and we also fixed a bug in the surveyor code. --- tests/resolv.c | 85 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 43 insertions(+), 42 deletions(-) (limited to 'tests') diff --git a/tests/resolv.c b/tests/resolv.c index 849b41cd..49d258c3 100644 --- a/tests/resolv.c +++ b/tests/resolv.c @@ -1,5 +1,6 @@ // // Copyright 2017 Garrett D'Amore +// Copyright 2017 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -130,103 +131,103 @@ TestMain("Resolver", { nni_init(); Convey("Google DNS IPv4 resolves", { - nni_aio aio; + nni_aio * aio; const char * str; nng_sockaddr sa; - memset(&aio, 0, sizeof(aio)); + nni_aio_init(&aio, NULL, NULL); - aio.a_addr = &sa; + aio->a_addr = &sa; nni_plat_tcp_resolv("google-public-dns-a.google.com", "80", - NNG_AF_INET, 1, &aio); - nni_aio_wait(&aio); - So(nni_aio_result(&aio) == 0); + NNG_AF_INET, 1, aio); + nni_aio_wait(aio); + So(nni_aio_result(aio) == 0); So(sa.s_un.s_in.sa_family == NNG_AF_INET); So(sa.s_un.s_in.sa_port == ntohs(80)); str = ip4tostr(&sa.s_un.s_in.sa_addr); So(strcmp(str, "8.8.8.8") == 0); - nni_aio_fini(&aio); + nni_aio_fini(aio); }); Convey("Numeric UDP resolves", { - nni_aio aio; + nni_aio * aio; const char * str; nng_sockaddr sa; - memset(&aio, 0, sizeof(aio)); + nni_aio_init(&aio, NULL, NULL); - aio.a_addr = &sa; - nni_plat_udp_resolv("8.8.4.4", "69", NNG_AF_INET, 1, &aio); - nni_aio_wait(&aio); - So(nni_aio_result(&aio) == 0); + aio->a_addr = &sa; + nni_plat_udp_resolv("8.8.4.4", "69", NNG_AF_INET, 1, aio); + nni_aio_wait(aio); + So(nni_aio_result(aio) == 0); So(sa.s_un.s_in.sa_family == NNG_AF_INET); So(sa.s_un.s_in.sa_port == ntohs(69)); str = ip4tostr(&sa.s_un.s_in.sa_addr); So(strcmp(str, "8.8.4.4") == 0); - nni_aio_fini(&aio); + nni_aio_fini(aio); }); Convey("Numeric v4 resolves", { - nni_aio aio; + nni_aio * aio; const char * str; nng_sockaddr sa; - memset(&aio, 0, sizeof(aio)); + nni_aio_init(&aio, NULL, NULL); - aio.a_addr = &sa; - nni_plat_tcp_resolv("8.8.4.4", "80", NNG_AF_INET, 1, &aio); - nni_aio_wait(&aio); - So(nni_aio_result(&aio) == 0); + aio->a_addr = &sa; + nni_plat_tcp_resolv("8.8.4.4", "80", NNG_AF_INET, 1, aio); + nni_aio_wait(aio); + So(nni_aio_result(aio) == 0); So(sa.s_un.s_in.sa_family == NNG_AF_INET); So(sa.s_un.s_in.sa_port == ntohs(80)); str = ip4tostr(&sa.s_un.s_in.sa_addr); So(strcmp(str, "8.8.4.4") == 0); - nni_aio_fini(&aio); + nni_aio_fini(aio); }); Convey("Numeric v6 resolves", { - nni_aio aio; + nni_aio * aio; const char * str; nng_sockaddr sa; - memset(&aio, 0, sizeof(aio)); + nni_aio_init(&aio, NULL, NULL); - aio.a_addr = &sa; - nni_plat_tcp_resolv("::1", "80", NNG_AF_INET6, 1, &aio); - nni_aio_wait(&aio); - So(nni_aio_result(&aio) == 0); + aio->a_addr = &sa; + nni_plat_tcp_resolv("::1", "80", NNG_AF_INET6, 1, aio); + nni_aio_wait(aio); + So(nni_aio_result(aio) == 0); So(sa.s_un.s_in6.sa_family == NNG_AF_INET6); So(sa.s_un.s_in6.sa_port == ntohs(80)); str = ip6tostr(&sa.s_un.s_in6.sa_addr); So(strcmp(str, "::1") == 0); - nni_aio_fini(&aio); + nni_aio_fini(aio); }); Convey("TCP Name service resolves", { - nni_aio aio; + nni_aio * aio; const char * str; nng_sockaddr sa; - memset(&aio, 0, sizeof(aio)); + nni_aio_init(&aio, NULL, NULL); - aio.a_addr = &sa; - nni_plat_tcp_resolv("8.8.4.4", "http", NNG_AF_INET, 1, &aio); - nni_aio_wait(&aio); - So(nni_aio_result(&aio) == 0); + aio->a_addr = &sa; + nni_plat_tcp_resolv("8.8.4.4", "http", NNG_AF_INET, 1, aio); + nni_aio_wait(aio); + So(nni_aio_result(aio) == 0); So(sa.s_un.s_in.sa_family == NNG_AF_INET); So(sa.s_un.s_in.sa_port == ntohs(80)); str = ip4tostr(&sa.s_un.s_in.sa_addr); So(strcmp(str, "8.8.4.4") == 0); - nni_aio_fini(&aio); + nni_aio_fini(aio); }); Convey("UDP Name service resolves", { - nni_aio aio; + nni_aio * aio; const char * str; nng_sockaddr sa; - memset(&aio, 0, sizeof(aio)); + nni_aio_init(&aio, NULL, NULL); - aio.a_addr = &sa; - nni_plat_udp_resolv("8.8.4.4", "tftp", NNG_AF_INET, 1, &aio); - nni_aio_wait(&aio); - So(nni_aio_result(&aio) == 0); + aio->a_addr = &sa; + nni_plat_udp_resolv("8.8.4.4", "tftp", NNG_AF_INET, 1, aio); + nni_aio_wait(aio); + So(nni_aio_result(aio) == 0); So(sa.s_un.s_in.sa_family == NNG_AF_INET); So(sa.s_un.s_in.sa_port == ntohs(69)); str = ip4tostr(&sa.s_un.s_in.sa_addr); So(strcmp(str, "8.8.4.4") == 0); - nni_aio_fini(&aio); + nni_aio_fini(aio); }); nni_fini(); -- cgit v1.2.3-70-g09d2