nameserv: allow concurrent asynchronous requests
Allow multiple resolving threads to be running at the same time in order to support multiple callers, but use a mutex to avoid sending multiple requests to the privops helper. This will be needed for the NTS-KE server negotiation.
This commit is contained in:
parent
e43d699973
commit
24538fe3e9
1 changed files with 3 additions and 6 deletions
|
@ -51,7 +51,7 @@ struct DNS_Async_Instance {
|
|||
int pipe[2];
|
||||
};
|
||||
|
||||
static int resolving_threads = 0;
|
||||
static pthread_mutex_t privops_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
|
@ -60,7 +60,9 @@ start_resolving(void *anything)
|
|||
{
|
||||
struct DNS_Async_Instance *inst = (struct DNS_Async_Instance *)anything;
|
||||
|
||||
pthread_mutex_lock(&privops_lock);
|
||||
inst->status = PRV_Name2IPAddress(inst->name, inst->addresses, DNS_MAX_ADDRESSES);
|
||||
pthread_mutex_unlock(&privops_lock);
|
||||
|
||||
/* Notify the main thread that the result is ready */
|
||||
if (write(inst->pipe[1], "", 1) < 0)
|
||||
|
@ -81,8 +83,6 @@ end_resolving(int fd, int event, void *anything)
|
|||
LOG_FATAL("pthread_join() failed");
|
||||
}
|
||||
|
||||
resolving_threads--;
|
||||
|
||||
SCH_RemoveFileHandler(inst->pipe[0]);
|
||||
close(inst->pipe[0]);
|
||||
close(inst->pipe[1]);
|
||||
|
@ -116,9 +116,6 @@ DNS_Name2IPAddressAsync(const char *name, DNS_NameResolveHandler handler, void *
|
|||
UTI_FdSetCloexec(inst->pipe[0]);
|
||||
UTI_FdSetCloexec(inst->pipe[1]);
|
||||
|
||||
resolving_threads++;
|
||||
assert(resolving_threads <= 1);
|
||||
|
||||
if (pthread_create(&inst->thread, NULL, start_resolving, inst)) {
|
||||
LOG_FATAL("pthread_create() failed");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue