mirror of https://github.com/getdnsapi/getdns.git
Convert test programs to not use libevent.
This commit is contained in:
parent
b4eb5d1ea5
commit
8e144d5648
|
@ -76,7 +76,7 @@ tests_list: tests_list.o testmessages.o
|
||||||
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ tests_list.o testmessages.o
|
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ tests_list.o testmessages.o
|
||||||
|
|
||||||
tests_stub_async: tests_stub_async.o testmessages.o
|
tests_stub_async: tests_stub_async.o testmessages.o
|
||||||
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -lgetdns_ext_event $(LDLIBS) -o $@ tests_stub_async.o testmessages.o
|
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ tests_stub_async.o testmessages.o
|
||||||
|
|
||||||
tests_stub_sync: tests_stub_sync.o
|
tests_stub_sync: tests_stub_sync.o
|
||||||
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ tests_stub_sync.o
|
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ tests_stub_sync.o
|
||||||
|
@ -97,7 +97,7 @@ check_getdns_ev: check_getdns.o check_getdns_common.o check_getdns_context_set_t
|
||||||
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -lpthread -lgetdns_ext_ev $(EXTENSION_LIBEV_LDFLAGS) $(EXTENSION_LIBEV_EXT_LIBS) $(LDLIBS) -o $@ check_getdns.o check_getdns_common.o check_getdns_context_set_timeout.o check_getdns_libev.o
|
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -lpthread -lgetdns_ext_ev $(EXTENSION_LIBEV_LDFLAGS) $(EXTENSION_LIBEV_EXT_LIBS) $(LDLIBS) -o $@ check_getdns.o check_getdns_common.o check_getdns_context_set_timeout.o check_getdns_libev.o
|
||||||
|
|
||||||
tests_dnssec: tests_dnssec.o testmessages.o
|
tests_dnssec: tests_dnssec.o testmessages.o
|
||||||
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -lgetdns_ext_event $(LDLIBS) -o $@ tests_dnssec.o testmessages.o
|
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ tests_dnssec.o testmessages.o
|
||||||
|
|
||||||
|
|
||||||
test: all
|
test: all
|
||||||
|
|
|
@ -34,17 +34,12 @@
|
||||||
|
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#ifdef HAVE_EVENT2_EVENT_H
|
|
||||||
# include <event2/event.h>
|
|
||||||
#else
|
|
||||||
# include <event.h>
|
|
||||||
#endif
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "testmessages.h"
|
#include "testmessages.h"
|
||||||
#include <getdns/getdns.h>
|
#include <getdns/getdns.h>
|
||||||
#include <getdns/getdns_ext_libevent.h>
|
#include <getdns/getdns_extra.h>
|
||||||
|
|
||||||
/* Set up the callback function, which will also do the processing of the results */
|
/* Set up the callback function, which will also do the processing of the results */
|
||||||
void
|
void
|
||||||
|
@ -135,7 +130,6 @@ callbackfn(struct getdns_context *context,
|
||||||
getdns_list_destroy(trust_anchors);
|
getdns_list_destroy(trust_anchors);
|
||||||
} while (0);
|
} while (0);
|
||||||
getdns_dict_destroy(response);
|
getdns_dict_destroy(response);
|
||||||
(void) event_base_loopexit((struct event_base *)userarg, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -144,9 +138,9 @@ main(int argc, char** argv)
|
||||||
const char *name = argc > 1 ? argv[1] : "www.example.com";
|
const char *name = argc > 1 ? argv[1] : "www.example.com";
|
||||||
struct getdns_context *context;
|
struct getdns_context *context;
|
||||||
struct getdns_dict *extensions;
|
struct getdns_dict *extensions;
|
||||||
struct event_base *event_base = NULL;
|
|
||||||
getdns_transaction_t transaction_id = 0;
|
getdns_transaction_t transaction_id = 0;
|
||||||
getdns_return_t r;
|
getdns_return_t r;
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
r = getdns_context_create(&context, 1);
|
r = getdns_context_create(&context, 1);
|
||||||
if (r != GETDNS_RETURN_GOOD) {
|
if (r != GETDNS_RETURN_GOOD) {
|
||||||
|
@ -172,24 +166,25 @@ main(int argc, char** argv)
|
||||||
goto done_destroy_extensions;
|
goto done_destroy_extensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create an event base and put it in the context */
|
|
||||||
event_base = event_base_new();
|
|
||||||
if (event_base == NULL) {
|
|
||||||
fprintf(stderr, "Trying to create the event base failed.");
|
|
||||||
r = GETDNS_RETURN_GENERIC_ERROR;
|
|
||||||
goto done_destroy_extensions;
|
|
||||||
}
|
|
||||||
(void) getdns_extension_set_libevent_base(context, event_base);
|
|
||||||
|
|
||||||
/* Make the call */
|
/* Make the call */
|
||||||
r = getdns_address(context, name, extensions, event_base,
|
r = getdns_address(context, name, extensions, NULL,
|
||||||
&transaction_id, callbackfn);
|
&transaction_id, callbackfn);
|
||||||
if (r == GETDNS_RETURN_BAD_DOMAIN_NAME) {
|
if (r == GETDNS_RETURN_BAD_DOMAIN_NAME) {
|
||||||
fprintf(stderr, "Bad domain name: %s.", name);
|
fprintf(stderr, "Bad domain name: %s.", name);
|
||||||
goto done_destroy_extensions;
|
goto done_destroy_extensions;
|
||||||
}
|
}
|
||||||
/* Call the event loop */
|
/* Call the event loop */
|
||||||
event_base_dispatch(event_base);
|
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);
|
||||||
|
if (getdns_context_process_async(context) != GETDNS_RETURN_GOOD) {
|
||||||
|
// context destroyed
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Clean up */
|
/* Clean up */
|
||||||
done_destroy_extensions:
|
done_destroy_extensions:
|
||||||
|
@ -197,12 +192,5 @@ done_destroy_extensions:
|
||||||
done_destroy_context:
|
done_destroy_context:
|
||||||
getdns_context_destroy(context);
|
getdns_context_destroy(context);
|
||||||
|
|
||||||
/* Event base must be destroyed after the context, because
|
|
||||||
* the context has to re-register its sockets from the eventbase,
|
|
||||||
* who has to communicate this to the system event-mechanism.
|
|
||||||
*/
|
|
||||||
if (event_base)
|
|
||||||
event_base_free(event_base);
|
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,17 +33,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#ifdef HAVE_EVENT2_EVENT_H
|
|
||||||
# include <event2/event.h>
|
|
||||||
#else
|
|
||||||
# include <event.h>
|
|
||||||
#endif
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "testmessages.h"
|
#include "testmessages.h"
|
||||||
#include <getdns/getdns.h>
|
#include <getdns/getdns.h>
|
||||||
#include <getdns/getdns_ext_libevent.h>
|
#include <getdns/getdns_extra.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
/* Set up the callback function, which will also do the processing of the results */
|
/* Set up the callback function, which will also do the processing of the results */
|
||||||
|
@ -85,19 +80,6 @@ main(int argc, char** argv)
|
||||||
|
|
||||||
getdns_context_set_timeout(this_context, 5000);
|
getdns_context_set_timeout(this_context, 5000);
|
||||||
/* Create an event base and put it in the context using the unknown function name */
|
/* Create an event base and put it in the context using the unknown function name */
|
||||||
struct event_base *this_event_base;
|
|
||||||
this_event_base = event_base_new();
|
|
||||||
if (this_event_base == NULL) {
|
|
||||||
fprintf(stderr, "Trying to create the event base failed.");
|
|
||||||
getdns_context_destroy(this_context);
|
|
||||||
return (GETDNS_RETURN_GENERIC_ERROR);
|
|
||||||
}
|
|
||||||
if (getdns_extension_set_libevent_base(this_context,
|
|
||||||
this_event_base) != GETDNS_RETURN_GOOD) {
|
|
||||||
fprintf(stderr, "Setting event base failed.");
|
|
||||||
getdns_context_destroy(this_context);
|
|
||||||
return (GETDNS_RETURN_GENERIC_ERROR);
|
|
||||||
}
|
|
||||||
/* Set up the getdns call */
|
/* Set up the getdns call */
|
||||||
const char *this_name = argc > 1 ? argv[1] : "getdnsapi.net";
|
const char *this_name = argc > 1 ? argv[1] : "getdnsapi.net";
|
||||||
char *this_userarg = "somestring"; // Could add things here to help identify this call
|
char *this_userarg = "somestring"; // Could add things here to help identify this call
|
||||||
|
@ -111,29 +93,25 @@ main(int argc, char** argv)
|
||||||
fprintf(stderr, "A bad domain name was used: %s. Exiting.",
|
fprintf(stderr, "A bad domain name was used: %s. Exiting.",
|
||||||
this_name);
|
this_name);
|
||||||
getdns_context_destroy(this_context);
|
getdns_context_destroy(this_context);
|
||||||
event_base_free(this_event_base);
|
|
||||||
return (GETDNS_RETURN_GENERIC_ERROR);
|
return (GETDNS_RETURN_GENERIC_ERROR);
|
||||||
}
|
}
|
||||||
// dns_request_return = getdns_service(this_context, this_name, NULL, this_userarg, &this_transaction_id,
|
|
||||||
// this_callbackfn);
|
|
||||||
// if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME)
|
|
||||||
// {
|
|
||||||
// fprintf(stderr, "A bad domain name was used: %s. Exiting.", this_name);
|
|
||||||
// return(GETDNS_RETURN_GENERIC_ERROR);
|
|
||||||
// }
|
|
||||||
else {
|
else {
|
||||||
/* Call the event loop */
|
/* Call the event loop */
|
||||||
event_base_loop(this_event_base, EVLOOP_ONCE);
|
struct timeval tv;
|
||||||
while (getdns_context_get_num_pending_requests(this_context, NULL) > 0) {
|
while (getdns_context_get_num_pending_requests(this_context, &tv) > 0) {
|
||||||
event_base_loop(this_event_base, EVLOOP_ONCE);
|
int fd = getdns_context_fd(this_context);
|
||||||
|
fd_set read_fds;
|
||||||
|
FD_ZERO(&read_fds);
|
||||||
|
FD_SET(fd, &read_fds);
|
||||||
|
select(fd + 1, &read_fds, NULL, NULL, &tv);
|
||||||
|
if (getdns_context_process_async(this_context) != GETDNS_RETURN_GOOD) {
|
||||||
|
// context destroyed
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// TODO: check the return value above
|
|
||||||
}
|
}
|
||||||
/* Clean up */
|
/* Clean up */
|
||||||
getdns_context_destroy(this_context);
|
getdns_context_destroy(this_context);
|
||||||
/* the event base can only be free'd after the context has removed
|
|
||||||
* all of its events from it */
|
|
||||||
event_base_free(this_event_base);
|
|
||||||
/* Assuming we get here, leave gracefully */
|
/* Assuming we get here, leave gracefully */
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
} /* main */
|
} /* main */
|
||||||
|
|
Loading…
Reference in New Issue