X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;ds=inline;f=src%2Fadns.c;h=758c08088bd5f6fbbe97b23afae94f1143fbbed5;hb=45aaef5c448fad77835c9c56ebe1d05002e06d7e;hp=08fd8123754aa720c07b2e467815f0a41a422e81;hpb=6558e508cc80ec97ec9c5bbcf7df922e13ed5b2e;p=meshlink diff --git a/src/adns.c b/src/adns.c index 08fd8123..758c0808 100644 --- a/src/adns.c +++ b/src/adns.c @@ -20,7 +20,6 @@ #include "system.h" #include -#include #include "adns.h" #include "devtools.h" @@ -85,8 +84,9 @@ static void adns_cb_handler(event_loop_t *loop, void *data) { } void init_adns(meshlink_handle_t *mesh) { - signal_add(&mesh->loop, &mesh->adns_signal, adns_cb_handler, mesh, 1); meshlink_queue_init(&mesh->adns_queue); + meshlink_queue_init(&mesh->adns_done_queue); + signal_add(&mesh->loop, &mesh->adns_signal, adns_cb_handler, mesh, 1); pthread_create(&mesh->adns_thread, NULL, adns_loop, mesh); } @@ -107,7 +107,7 @@ void exit_adns(meshlink_handle_t *mesh) { abort(); } - assert(pthread_cond_signal(&mesh->adns_cond) == 0); + pthread_cond_signal(&mesh->adns_cond); pthread_join(mesh->adns_thread, NULL); meshlink_queue_exit(&mesh->adns_queue); @@ -128,7 +128,7 @@ void adns_queue(meshlink_handle_t *mesh, char *host, char *serv, adns_cb_t cb, v abort(); } - assert(pthread_cond_signal(&mesh->adns_cond) == 0); + pthread_cond_signal(&mesh->adns_cond); } struct adns_blocking_info { @@ -157,16 +157,18 @@ static void *adns_blocking_handler(void *data) { info->ai = NULL; } - assert(pthread_mutex_lock(&info->mutex) == 0); + if(pthread_mutex_lock(&info->mutex) != 0) { + abort(); + } bool cleanup = info->done; if(!info->done) { info->done = true; - assert(pthread_cond_signal(&info->cond) == 0); + pthread_cond_signal(&info->cond); } - assert(pthread_mutex_unlock(&info->mutex) == 0); + pthread_mutex_unlock(&info->mutex); if(cleanup) { free(info->host); @@ -184,8 +186,8 @@ struct addrinfo *adns_blocking_request(meshlink_handle_t *mesh, char *host, char info->host = host; info->serv = serv; info->socktype = socktype; - assert(pthread_mutex_init(&info->mutex, NULL) == 0); - assert(pthread_cond_init(&info->cond, NULL) == 0); + pthread_mutex_init(&info->mutex, NULL); + pthread_cond_init(&info->cond, NULL); struct timespec deadline; clock_gettime(CLOCK_REALTIME, &deadline); @@ -199,11 +201,14 @@ struct addrinfo *adns_blocking_request(meshlink_handle_t *mesh, char *host, char free(info); return NULL; } else { - assert(pthread_detach(thread) == 0); + pthread_detach(thread); + } + + if(pthread_mutex_lock(&info->mutex) != 0) { + abort(); } - assert(pthread_mutex_lock(&info->mutex) == 0); - assert(pthread_cond_timedwait(&info->cond, &info->mutex, &deadline) == 0); + pthread_cond_timedwait(&info->cond, &info->mutex, &deadline); struct addrinfo *result = NULL; bool cleanup = info->done; @@ -215,7 +220,7 @@ struct addrinfo *adns_blocking_request(meshlink_handle_t *mesh, char *host, char info->done = true; } - assert(pthread_mutex_unlock(&info->mutex) == 0); + pthread_mutex_unlock(&info->mutex); if(cleanup) { free(info->host);