Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions lib/dnsthread/dnsthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,20 +265,20 @@ dnsthread_resolveone(DNSTHREAD T, const char * addr,
T->callback = callback;
T->cookie = cookie;

/* We want a callback when the worker thread pokes us. */
if (events_network_register(callback_resolveone, T, T->wakeupsock[1],
EVENTS_NETWORK_OP_READ)) {
warnp("Error registering wakeup listener");
goto err2;
}

/* There is now work for the thread to do. */
T->state = THREAD_HASWORK;

/* Wake up the worker thread. */
if ((rc = pthread_cond_signal(&T->cv)) != 0) {
warn0("pthread_cond_signal: %s", strerror(rc));
goto err1;
}

/* We want a callback when the worker thread pokes us. */
if (events_network_register(callback_resolveone, T, T->wakeupsock[1],
EVENTS_NETWORK_OP_READ)) {
warnp("Error registering wakeup listener");
goto err1;
goto err3;
}

ealready:
Expand All @@ -295,6 +295,11 @@ dnsthread_resolveone(DNSTHREAD T, const char * addr,
/* Success! */
return (0);

err3:
T->state = THREAD_SLEEPING;
events_network_cancel(T->wakeupsock[1], EVENTS_NETWORK_OP_READ);
err2:
free(T->addr);
err1:
pthread_mutex_unlock(&T->mtx);
err0:
Expand Down