diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-08-31 17:59:01 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-09-22 11:47:07 -0700 |
| commit | d72076207a2fad96ff014a81366868fb47a0ed1b (patch) | |
| tree | 5a4f67ab607ef6690e983c2d1ab2c64062027e52 /tests/resolv.c | |
| parent | 366f3e5d14c5f891655ad1fa2b3cfa9a56b8830d (diff) | |
| download | nng-d72076207a2fad96ff014a81366868fb47a0ed1b.tar.gz nng-d72076207a2fad96ff014a81366868fb47a0ed1b.tar.bz2 nng-d72076207a2fad96ff014a81366868fb47a0ed1b.zip | |
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.
Diffstat (limited to 'tests/resolv.c')
| -rw-r--r-- | tests/resolv.c | 85 |
1 files changed, 43 insertions, 42 deletions
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 <garrett@damore.org> +// Copyright 2017 Capitar IT Group BV <info@capitar.com> // // 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(); |
