Last active
August 29, 2015 13:57
-
-
Save ngoyal/9436881 to your computer and use it in GitHub Desktop.
getdns_context_destroy in the callback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Set up the callback function, which will also do the processing of the results */ | |
void this_callbackfn(getdns_context *this_context, | |
getdns_callback_type_t this_callback_type, | |
getdns_dict *this_response, | |
void *this_userarg, | |
getdns_transaction_t this_transaction_id) | |
{ | |
// The first callback to receive this triggers the other callbacks | |
// to be called as if they were canceled. They end up calling | |
// destroy again on the same context already being destroyed | |
// before returning and printing "Context destroyed". | |
// This can also be triggered if a request was canceled or timed | |
// out and other requests are pending. | |
getdns_context_destroy(this_context); | |
printf("Context destroyed\n"); | |
} | |
int main() | |
{ | |
/* Create the DNS context for this call */ | |
getdns_context *this_context = NULL; | |
getdns_return_t context_create_return = getdns_context_create(&this_context, 1); | |
/* Create an event base and put it in the context using the unknown function name */ | |
struct event_base *this_event_base = event_base_new(); | |
getdns_extension_set_libevent_base(this_context, this_event_base); | |
// Fire off a bunch of requests | |
for (int i = 0; i < 10; ++i) { | |
getdns_address(this_context, this_name, | |
NULL, NULL, NULL, this_callbackfn); | |
} | |
/* Call the event loop */ | |
event_base_dispatch(this_event_base); | |
event_base_free(this_event_base); | |
/* Assuming we get here, leave gracefully */ | |
exit(EXIT_SUCCESS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment