[getdns-users] Context reuse?

Willem Toorop willem at nlnetlabs.nl
Wed Jun 28 12:33:10 UTC 2017


Op 27-06-17 om 15:40 schreef James Royalty:
> I'm using getdns in a long-running async (libuv) application.  Should
> I be reusing a single context for new requests (while others are in
> flight)?  Or should I be creating a new context for each resolution
> request?

Hi James,

You should use a single context.

Did you register the uv event loop with the context?
Something like this:


#include <getdns/getdns.h>
#include <getdns/getdns_extra.h>
#include <getdns/getdns_ext_libuv.h>

int main()
{
	getdns_return_t r;
	getdns_context *context = NULL;
	uv_loop_t* loop = uv_default_loop();

	if ((r = getdns_create_context(&context, 1))
		fprintf(stderr, "Error creating context");

	else if ((r = getdns_extension_set_libuv_loop(context, loop))
		fprintf(stderr, "Error registering event loop");
	else {
		// your stuff scheduling against loop,
		// doing async getdns requests etc.
	
		uv_run(loop, UV_RUN_DEFAULT); // Run the uv loop
	}
	if (r)
		fprintf(stderr, ": %s\n", getdns_errorstr_by_id(r));
	getdns_context_destroy(context);
	return r ? EXIT_FAILURE : EXIT_SUCCES;
}

Then all getdns I/O will use the libuv loop.  Even the full recursive
requests (done with libunbound under the hood).

Also don't forget to link against libgetdns_ext_uv.so then too!
eg: -luv -lgetdns -lgetdns_ext_uv


Cheers,
-- Willem
> 
> Cheers!
> --
> J
> _______________________________________________
> Users mailing list
> Users at getdnsapi.net
> https://getdnsapi.net/mailman/listinfo/users
> 




More information about the Users mailing list