From b548cce9d872ba9fa9819f1f2d5c956409535145 Mon Sep 17 00:00:00 2001 From: Neel Goyal Date: Fri, 28 Feb 2014 19:24:09 -0500 Subject: [PATCH] Add a method to change unbound async mode (getdns_extra) between fork and thread --- src/context.c | 15 +++++++++++++++ src/getdns/getdns_extra.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/context.c b/src/context.c index 92e355bd..d6f0f1fb 100644 --- a/src/context.c +++ b/src/context.c @@ -1791,4 +1791,19 @@ getdns_context_set_return_dnssec_status(getdns_context* context, int enabled) { return GETDNS_RETURN_GOOD; } +getdns_return_t +getdns_context_set_use_threads(getdns_context* context, int use_threads) { + RETURN_IF_NULL(context, GETDNS_RETURN_INVALID_PARAMETER); + if (context->resolution_type_set != 0) { + /* already setup */ + return GETDNS_RETURN_CONTEXT_UPDATE_FAIL; + } + int r = 0; + if (use_threads) + r = ub_ctx_async(context->unbound_ctx, 1); + else + r = ub_ctx_async(context->unbound_ctx, 0); + return r == 0 ? GETDNS_RETURN_GOOD : GETDNS_RETURN_CONTEXT_UPDATE_FAIL; +} + /* context.c */ diff --git a/src/getdns/getdns_extra.h b/src/getdns/getdns_extra.h index eeba17dd..c17996e2 100644 --- a/src/getdns/getdns_extra.h +++ b/src/getdns/getdns_extra.h @@ -55,6 +55,8 @@ int getdns_context_fd(getdns_context* context); /* process async reqs */ getdns_return_t getdns_context_process_async(getdns_context* context); +/* tells underlying unbound to use background threads or fork */ +getdns_return_t getdns_context_set_use_threads(getdns_context* context, int use_threads); /* extensions */ typedef void (*getdns_timeout_callback) (void* userarg);