diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-07-06 14:45:53 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-07-06 14:45:53 -0700 |
| commit | 3da27f7c9c1077f285f53b1e80a1befffe104770 (patch) | |
| tree | dad07400dced42b061d036c9dd86aaf501592dfc /src | |
| parent | 82c70435ec9be9c607de4fbd62d4de9ae7d7c081 (diff) | |
| download | nng-3da27f7c9c1077f285f53b1e80a1befffe104770.tar.gz nng-3da27f7c9c1077f285f53b1e80a1befffe104770.tar.bz2 nng-3da27f7c9c1077f285f53b1e80a1befffe104770.zip | |
Fixes for async resolver, plus a test suite for it.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/aio.c | 4 | ||||
| -rw-r--r-- | src/platform/posix/posix_impl.h | 2 | ||||
| -rw-r--r-- | src/platform/posix/posix_resolv_gai.c | 12 | ||||
| -rw-r--r-- | src/platform/posix/posix_thread.c | 12 |
4 files changed, 26 insertions, 4 deletions
diff --git a/src/core/aio.c b/src/core/aio.c index e1d7bdae..c7d2b0b0 100644 --- a/src/core/aio.c +++ b/src/core/aio.c @@ -66,6 +66,10 @@ nni_aio_fini(nni_aio *aio) // At this point the AIO is done. nni_cv_fini(&aio->a_cv); nni_mtx_fini(&aio->a_lk); + + if ((aio->a_naddrs != 0) && (aio->a_addrs != NULL)) { + NNI_FREE_STRUCTS(aio->a_addrs, aio->a_naddrs); + } } diff --git a/src/platform/posix/posix_impl.h b/src/platform/posix/posix_impl.h index 3a2e29e1..407adf74 100644 --- a/src/platform/posix/posix_impl.h +++ b/src/platform/posix/posix_impl.h @@ -69,5 +69,7 @@ struct nni_plat_cv { extern int nni_posix_pollq_sysinit(void); extern void nni_posix_pollq_sysfini(void); +extern int nni_posix_resolv_sysinit(void); +extern void nni_posix_resolv_sysfini(void); #endif // PLATFORM_POSIX_IMPL_H diff --git a/src/platform/posix/posix_resolv_gai.c b/src/platform/posix/posix_resolv_gai.c index 2b2a8436..82febf6e 100644 --- a/src/platform/posix/posix_resolv_gai.c +++ b/src/platform/posix/posix_resolv_gai.c @@ -167,7 +167,7 @@ nni_posix_resolv_task(void *arg) } } // If the only results were not IPv4 or IPv6... - if (aio->a_addrs == 0) { + if (aio->a_naddrs == 0) { rv = NNG_EADDRINVAL; break; } @@ -231,6 +231,9 @@ nni_posix_resolv_ip(const char *host, const char *serv, int passive, nni_posix_resolv_item *item; int rv; + if ((aio->a_naddrs != 0) && (aio->a_addrs != NULL)) { + NNI_FREE_STRUCTS(aio->a_addrs, aio->a_naddrs); + } if ((item = NNI_ALLOC_STRUCT(item)) == NULL) { nni_aio_finish(aio, NNG_ENOMEM, 0); return; @@ -254,6 +257,7 @@ nni_posix_resolv_ip(const char *host, const char *serv, int passive, item->name = host; item->serv = serv; item->proto = proto; + item->aio = aio; nni_mtx_lock(&nni_posix_resolv_mtx); // If we were stopped, we're done... @@ -272,7 +276,7 @@ nni_posix_resolv_ip(const char *host, const char *serv, int passive, void -nni_plat_resolv_tcp(const char *host, const char *serv, int family, +nni_plat_tcp_resolv(const char *host, const char *serv, int family, int passive, nni_aio *aio) { nni_posix_resolv_ip(host, serv, passive, family, IPPROTO_TCP, aio); @@ -280,7 +284,7 @@ nni_plat_resolv_tcp(const char *host, const char *serv, int family, int -nni_posix_resolv_init(void) +nni_posix_resolv_sysinit(void) { int rv; @@ -296,7 +300,7 @@ nni_posix_resolv_init(void) void -nni_posix_resolv_fini(void) +nni_posix_resolv_sysfini(void) { if (nni_posix_resolv_tq != NULL) { nni_taskq_fini(nni_posix_resolv_tq); diff --git a/src/platform/posix/posix_thread.c b/src/platform/posix/posix_thread.c index 171a87b9..4137984f 100644 --- a/src/platform/posix/posix_thread.c +++ b/src/platform/posix/posix_thread.c @@ -308,8 +308,20 @@ nni_plat_init(int (*helper)(void)) return (rv); } + if ((rv = nni_posix_resolv_sysinit()) != 0) { + pthread_mutex_unlock(&nni_plat_lock); + nni_posix_pollq_sysfini(); + (void) close(nni_plat_devnull); + pthread_mutexattr_destroy(&nni_mxattr); + pthread_condattr_destroy(&nni_cvattr); + pthread_attr_destroy(&nni_pthread_attr); + return (rv); + + } + if (pthread_atfork(NULL, NULL, nni_atfork_child) != 0) { pthread_mutex_unlock(&nni_plat_lock); + nni_posix_resolv_sysfini(); nni_posix_pollq_sysfini(); (void) close(devnull); pthread_mutexattr_destroy(&nni_mxattr); |
