mirror of https://github.com/getdnsapi/getdns.git
Fix an issue with timeouts in the async
This commit is contained in:
parent
c658b55d73
commit
6a07664ef9
|
@ -1330,6 +1330,8 @@ getdns_context_schedule_timeout(struct getdns_context* context,
|
||||||
}
|
}
|
||||||
node->key = &(timeout_data->transaction_id);
|
node->key = &(timeout_data->transaction_id);
|
||||||
node->data = timeout_data;
|
node->data = timeout_data;
|
||||||
|
node->left = NULL;
|
||||||
|
node->right = NULL;
|
||||||
if (!ldns_rbtree_insert(context->timeouts_by_id, node)) {
|
if (!ldns_rbtree_insert(context->timeouts_by_id, node)) {
|
||||||
/* free the node */
|
/* free the node */
|
||||||
GETDNS_FREE(context->my_mf, timeout_data);
|
GETDNS_FREE(context->my_mf, timeout_data);
|
||||||
|
@ -1343,11 +1345,18 @@ getdns_context_schedule_timeout(struct getdns_context* context,
|
||||||
} else {
|
} else {
|
||||||
result = GETDNS_RETURN_GENERIC_ERROR;
|
result = GETDNS_RETURN_GENERIC_ERROR;
|
||||||
if (gettimeofday(&timeout_data->timeout_time, NULL) == 0) {
|
if (gettimeofday(&timeout_data->timeout_time, NULL) == 0) {
|
||||||
|
/* increment */
|
||||||
|
uint16_t num_secs = timeout / 1000;
|
||||||
|
/* timeout is in millis */
|
||||||
|
timeout_data->timeout_time.tv_sec += num_secs;
|
||||||
|
|
||||||
ldns_rbnode_t* id_node = GETDNS_MALLOC(context->my_mf, ldns_rbnode_t);
|
ldns_rbnode_t* id_node = GETDNS_MALLOC(context->my_mf, ldns_rbnode_t);
|
||||||
if (id_node) {
|
if (id_node) {
|
||||||
id_node->key = timeout_data;
|
id_node->key = timeout_data;
|
||||||
id_node->data = timeout_data;
|
id_node->data = timeout_data;
|
||||||
if (!ldns_rbtree_insert(context->timeouts_by_time, node)) {
|
id_node->left = NULL;
|
||||||
|
id_node->right = NULL;
|
||||||
|
if (!ldns_rbtree_insert(context->timeouts_by_time, id_node)) {
|
||||||
GETDNS_FREE(context->my_mf, id_node);
|
GETDNS_FREE(context->my_mf, id_node);
|
||||||
} else {
|
} else {
|
||||||
result = GETDNS_RETURN_GOOD;
|
result = GETDNS_RETURN_GOOD;
|
||||||
|
@ -1359,7 +1368,7 @@ getdns_context_schedule_timeout(struct getdns_context* context,
|
||||||
GETDNS_FREE(context->my_mf, timeout_data);
|
GETDNS_FREE(context->my_mf, timeout_data);
|
||||||
GETDNS_FREE(context->my_mf, node);
|
GETDNS_FREE(context->my_mf, node);
|
||||||
}
|
}
|
||||||
return GETDNS_RETURN_GOOD;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
getdns_return_t
|
getdns_return_t
|
||||||
|
|
|
@ -40,9 +40,12 @@
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main (void)
|
main (int argc, char** argv)
|
||||||
{
|
{
|
||||||
int number_failed;
|
int number_failed;
|
||||||
|
if (argc > 1) {
|
||||||
|
event_loop_type = atoi(argv[1]);
|
||||||
|
}
|
||||||
SRunner *sr ;
|
SRunner *sr ;
|
||||||
|
|
||||||
Suite *getdns_general_suite(void);
|
Suite *getdns_general_suite(void);
|
||||||
|
|
|
@ -5,12 +5,16 @@
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <check.h>
|
#include <check.h>
|
||||||
#include <getdns/getdns.h>
|
#include <getdns/getdns.h>
|
||||||
|
#include <getdns/getdns_ext_libevent.h>
|
||||||
#include "check_getdns_common.h"
|
#include "check_getdns_common.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
int callback_called = 0;
|
int callback_called = 0;
|
||||||
int callback_completed = 0;
|
int callback_completed = 0;
|
||||||
int callback_canceled = 0;
|
int callback_canceled = 0;
|
||||||
uint16_t expected_changed_item = 0;
|
uint16_t expected_changed_item = 0;
|
||||||
|
int event_loop_type = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* extract_response extracts all of the various information
|
* extract_response extracts all of the various information
|
||||||
|
@ -287,3 +291,33 @@ void update_callbackfn(struct getdns_context *context,
|
||||||
"Expected changed_item == %d, got %d",
|
"Expected changed_item == %d, got %d",
|
||||||
changed_item, expected_changed_item);
|
changed_item, expected_changed_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void run_event_loop(struct getdns_context* context, struct event_base* base) {
|
||||||
|
if (event_loop_type == 0) {
|
||||||
|
while (getdns_context_get_num_pending_requests(context, NULL) > 0) {
|
||||||
|
event_base_loop(base, EVLOOP_ONCE);
|
||||||
|
}
|
||||||
|
} else if (event_loop_type == 1) {
|
||||||
|
struct timeval tv;
|
||||||
|
while (getdns_context_get_num_pending_requests(context, &tv) > 0) {
|
||||||
|
int fd = getdns_context_fd(context);
|
||||||
|
fd_set read_fds;
|
||||||
|
FD_ZERO(&read_fds);
|
||||||
|
FD_SET(fd, &read_fds);
|
||||||
|
select(fd + 1, &read_fds, NULL, NULL, &tv);
|
||||||
|
getdns_context_process_async(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct event_base* create_event_base(struct getdns_context* context) {
|
||||||
|
if (event_loop_type == 0) {
|
||||||
|
struct event_base* result = event_base_new();
|
||||||
|
ck_assert_msg(result != NULL, "Event base creation failed");
|
||||||
|
ASSERT_RC(getdns_extension_set_libevent_base(context, result),
|
||||||
|
GETDNS_RETURN_GOOD,
|
||||||
|
"Return code from getdns_extension_set_libevent_base()");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef _check_getdns_common_h_
|
#ifndef _check_getdns_common_h_
|
||||||
#define _check_getdns_common_h_
|
#define _check_getdns_common_h_
|
||||||
|
|
||||||
|
#include "check_getdns_libevent.h"
|
||||||
|
|
||||||
#define TRUE 1
|
#define TRUE 1
|
||||||
#define FALSE 0
|
#define FALSE 0
|
||||||
#define MAXLEN 200
|
#define MAXLEN 200
|
||||||
|
@ -9,6 +11,7 @@
|
||||||
extern int callback_completed;
|
extern int callback_completed;
|
||||||
extern int callback_canceled;
|
extern int callback_canceled;
|
||||||
extern uint16_t expected_changed_item;
|
extern uint16_t expected_changed_item;
|
||||||
|
extern int event_loop_type;
|
||||||
|
|
||||||
struct extracted_response {
|
struct extracted_response {
|
||||||
uint32_t top_answer_type;
|
uint32_t top_answer_type;
|
||||||
|
@ -64,20 +67,12 @@
|
||||||
* create an event base and put it in the
|
* create an event base and put it in the
|
||||||
* context.
|
* context.
|
||||||
*/
|
*/
|
||||||
#define EVENT_BASE_CREATE \
|
#define EVENT_BASE_CREATE event_base = create_event_base(context);
|
||||||
event_base = event_base_new(); \
|
|
||||||
ck_assert_msg(event_base != NULL, "Event base creation failed"); \
|
|
||||||
ASSERT_RC(getdns_extension_set_libevent_base(context, event_base), \
|
|
||||||
GETDNS_RETURN_GOOD, \
|
|
||||||
"Return code from getdns_extension_set_libevent_base()");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The RUN_EVENT_LOOP macro calls the event loop.
|
* The RUN_EVENT_LOOP macro calls the event loop.
|
||||||
*/
|
*/
|
||||||
#define RUN_EVENT_LOOP \
|
#define RUN_EVENT_LOOP run_event_loop(context, event_base);
|
||||||
while (getdns_context_get_num_pending_requests(context, NULL) > 0) { \
|
|
||||||
event_base_loop(event_base, EVLOOP_ONCE); \
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The LIST_CREATE macro simply creates a
|
* The LIST_CREATE macro simply creates a
|
||||||
|
@ -185,4 +180,9 @@
|
||||||
void update_callbackfn(struct getdns_context *context,
|
void update_callbackfn(struct getdns_context *context,
|
||||||
uint16_t changed_item);
|
uint16_t changed_item);
|
||||||
|
|
||||||
|
/* run the event loop */
|
||||||
|
void run_event_loop(struct getdns_context *context, struct event_base* event_base);
|
||||||
|
|
||||||
|
struct event_base* create_event_base(struct getdns_context* context);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue