[getdns-users] Context reuse?
James Royalty
jroyalty at gmail.com
Fri Jun 30 11:42:39 UTC 2017
Thanks Willem for the response! That's the gist of what I'm currently
doing so all good there.
Another question along these lines: What are the circumstances where
you'd want (or need) multiple contexts?
Cheers!
--
James
On Wed, Jun 28, 2017 at 9:33 AM, Willem Toorop <willem at nlnetlabs.nl> wrote:
> 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
More information about the Users
mailing list