}
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);
}
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);
abort();
}
- pthread_cond_signal(&mesh->adns_cond);
+ assert(pthread_cond_signal(&mesh->adns_cond) == 0);
}
struct adns_blocking_info {
char *host;
char *serv;
struct addrinfo *ai;
+ int socktype;
bool done;
};
-void *adns_blocking_handler(void *data) {
+static void *adns_blocking_handler(void *data) {
struct adns_blocking_info *info = data;
logger(info->mesh, MESHLINK_DEBUG, "Resolving %s port %s", info->host, info->serv);
devtool_adns_resolve_probe();
- if(getaddrinfo(info->host, info->serv, NULL, &info->ai)) {
+ struct addrinfo hint = {
+ .ai_family = AF_UNSPEC,
+ .ai_socktype = info->socktype,
+ };
+
+ if(getaddrinfo(info->host, info->serv, &hint, &info->ai)) {
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);
return NULL;
}
-struct addrinfo *adns_blocking_request(meshlink_handle_t *mesh, char *host, char *serv, int timeout) {
+struct addrinfo *adns_blocking_request(meshlink_handle_t *mesh, char *host, char *serv, int socktype, int timeout) {
struct adns_blocking_info *info = xzalloc(sizeof(*info));
info->mesh = mesh;
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);
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;
info->done = true;
}
- pthread_mutex_unlock(&info->mutex);
+ assert(pthread_mutex_unlock(&info->mutex) == 0);
if(cleanup) {
free(info->host);