mirror of https://github.com/getdnsapi/getdns.git
Add support for getting next timeout and number of pending events
This commit is contained in:
parent
b2ac3629f3
commit
c658b55d73
|
@ -1182,6 +1182,24 @@ int getdns_context_fd(struct getdns_context* context) {
|
|||
return ub_fd(context->unbound_ctx);
|
||||
}
|
||||
|
||||
int
|
||||
getdns_context_get_num_pending_requests(struct getdns_context* context,
|
||||
struct timeval* next_timeout) {
|
||||
RETURN_IF_NULL(context, GETDNS_RETURN_BAD_CONTEXT);
|
||||
int r = context->outbound_requests->count;
|
||||
if (r > 0) {
|
||||
if (!context->extension && next_timeout) {
|
||||
/* get the first timeout */
|
||||
ldns_rbnode_t* first = ldns_rbtree_first(context->timeouts_by_time);
|
||||
if (first) {
|
||||
getdns_timeout_data_t* timeout_data = (getdns_timeout_data_t*) first->data;
|
||||
*next_timeout = (timeout_data->timeout_time);
|
||||
}
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/* process async reqs */
|
||||
getdns_return_t getdns_context_process_async(struct getdns_context* context) {
|
||||
RETURN_IF_NULL(context, GETDNS_RETURN_BAD_CONTEXT);
|
||||
|
|
|
@ -135,6 +135,10 @@ void getdns_bindata_destroy(
|
|||
getdns_return_t getdns_extension_set_eventloop(struct getdns_context* context,
|
||||
getdns_eventloop_extension* extension, void* extension_data);
|
||||
|
||||
getdns_return_t
|
||||
getdns_extension_detach_eventloop(struct getdns_context* context);
|
||||
|
||||
|
||||
/* timeout scheduling */
|
||||
getdns_return_t getdns_context_schedule_timeout(struct getdns_context* context,
|
||||
getdns_transaction_t id, uint16_t timeout, getdns_timeout_callback callback,
|
||||
|
|
|
@ -872,9 +872,9 @@ getdns_context_set_extended_memory_functions(struct getdns_context *context,
|
|||
void (*free) (void *userarg, void *ptr)
|
||||
);
|
||||
|
||||
/* Extension */
|
||||
getdns_return_t
|
||||
getdns_extension_detach_eventloop(struct getdns_context* context);
|
||||
/* Async support */
|
||||
struct timeval;
|
||||
int getdns_context_get_num_pending_requests(struct getdns_context* context, struct timeval* next_timeout);
|
||||
|
||||
/* get the fd */
|
||||
int getdns_context_fd(struct getdns_context* context);
|
||||
|
|
|
@ -74,7 +74,10 @@
|
|||
/*
|
||||
* The RUN_EVENT_LOOP macro calls the event loop.
|
||||
*/
|
||||
#define RUN_EVENT_LOOP event_base_dispatch(event_base);
|
||||
#define RUN_EVENT_LOOP \
|
||||
while (getdns_context_get_num_pending_requests(context, NULL) > 0) { \
|
||||
event_base_loop(event_base, EVLOOP_ONCE); \
|
||||
}
|
||||
|
||||
/*
|
||||
* The LIST_CREATE macro simply creates a
|
||||
|
|
|
@ -122,12 +122,11 @@ main(int argc, char** argv)
|
|||
// return(GETDNS_RETURN_GENERIC_ERROR);
|
||||
// }
|
||||
else {
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 10;
|
||||
tv.tv_usec = 0;
|
||||
/* Call the event loop */
|
||||
event_base_loopexit(this_event_base, &tv);
|
||||
event_base_dispatch(this_event_base);
|
||||
event_base_loop(this_event_base, EVLOOP_ONCE);
|
||||
while (getdns_context_get_num_pending_requests(this_context, NULL) > 0) {
|
||||
event_base_loop(this_event_base, EVLOOP_ONCE);
|
||||
}
|
||||
// TODO: check the return value above
|
||||
}
|
||||
/* Clean up */
|
||||
|
|
Loading…
Reference in New Issue