X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fadns.c;h=56aed8b31c7d97ce79aef759349c0c43294b2f1b;hb=cb34e9341aa5e87867ca8c539c167f271e31b5bf;hp=01989ac5c71bdeb24602358841cfb5d5555dece6;hpb=91169c529883e08d7a0245b709483a22a83245ad;p=meshlink diff --git a/src/adns.c b/src/adns.c index 01989ac5..56aed8b3 100644 --- a/src/adns.c +++ b/src/adns.c @@ -85,8 +85,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 +108,7 @@ void exit_adns(meshlink_handle_t *mesh) { abort(); } - pthread_cond_signal(&mesh->adns_cond); + assert(pthread_cond_signal(&mesh->adns_cond) == 0); pthread_join(mesh->adns_thread, NULL); meshlink_queue_exit(&mesh->adns_queue); @@ -128,7 +129,7 @@ void adns_queue(meshlink_handle_t *mesh, char *host, char *serv, adns_cb_t cb, v abort(); } - pthread_cond_signal(&mesh->adns_cond); + assert(pthread_cond_signal(&mesh->adns_cond) == 0); } struct adns_blocking_info { @@ -157,16 +158,16 @@ static void *adns_blocking_handler(void *data) { info->ai = NULL; } - pthread_mutex_lock(&info->mutex); + assert(pthread_mutex_lock(&info->mutex) == 0); bool cleanup = info->done; if(!info->done) { info->done = true; - pthread_cond_signal(&info->cond); + assert(pthread_cond_signal(&info->cond) == 0); } - pthread_mutex_unlock(&info->mutex); + assert(pthread_mutex_unlock(&info->mutex) == 0); if(cleanup) { free(info->host); @@ -184,6 +185,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); struct timespec deadline; clock_gettime(CLOCK_REALTIME, &deadline); @@ -197,11 +200,11 @@ struct addrinfo *adns_blocking_request(meshlink_handle_t *mesh, char *host, char free(info); return NULL; } else { - pthread_detach(thread); + assert(pthread_detach(thread) == 0); } - pthread_mutex_lock(&info->mutex); - pthread_cond_timedwait(&info->cond, &info->mutex, &deadline); + assert(pthread_mutex_lock(&info->mutex) == 0); + assert(pthread_cond_timedwait(&info->cond, &info->mutex, &deadline) == 0); struct addrinfo *result = NULL; bool cleanup = info->done; @@ -213,7 +216,7 @@ struct addrinfo *adns_blocking_request(meshlink_handle_t *mesh, char *host, char info->done = true; } - pthread_mutex_unlock(&info->mutex); + assert(pthread_mutex_unlock(&info->mutex) == 0); if(cleanup) { free(info->host);