Add libuv support. Change event loop handling in tests

This commit is contained in:
Neel Goyal 2014-02-05 00:01:55 -05:00
parent c171b1ccc4
commit 562e2dd6df
15 changed files with 542 additions and 212 deletions

72
configure vendored
View File

@ -634,6 +634,8 @@ ac_includes_default="\
ac_subst_vars='LTLIBOBJS ac_subst_vars='LTLIBOBJS
LIBOBJS LIBOBJS
EXTENSION_LIBUV_OBJ
have_libuv
EXTENSION_LIBEVENT_OBJ EXTENSION_LIBEVENT_OBJ
have_libevent have_libevent
DOXYGEN DOXYGEN
@ -11144,6 +11146,7 @@ _ACEOF
esac esac
# libevent extension
have_libevent=1 have_libevent=1
EXTENSION_LIBEVENT_OBJ="extension/libevent.lo" EXTENSION_LIBEVENT_OBJ="extension/libevent.lo"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing event_loop" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing event_loop" >&5
@ -11223,6 +11226,75 @@ fi
# libuv extension
have_libuv=1
EXTENSION_LIBUV_OBJ="extension/libuv.lo"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing uv_run" >&5
$as_echo_n "checking for library containing uv_run... " >&6; }
if ${ac_cv_search_uv_run+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_func_search_save_LIBS=$LIBS
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char uv_run ();
int
main ()
{
return uv_run ();
;
return 0;
}
_ACEOF
for ac_lib in '' uv; do
if test -z "$ac_lib"; then
ac_res="none required"
else
ac_res=-l$ac_lib
LIBS="-l$ac_lib $ac_func_search_save_LIBS"
fi
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_search_uv_run=$ac_res
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext
if ${ac_cv_search_uv_run+:} false; then :
break
fi
done
if ${ac_cv_search_uv_run+:} false; then :
else
ac_cv_search_uv_run=no
fi
rm conftest.$ac_ext
LIBS=$ac_func_search_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_uv_run" >&5
$as_echo "$ac_cv_search_uv_run" >&6; }
ac_res=$ac_cv_search_uv_run
if test "$ac_res" != no; then :
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
$as_echo "#define HAVE_LIBUV 1" >>confdefs.h
else
have_libuv=0
EXTENSION_LIBUV_OBJ=""
fi
ac_config_files="$ac_config_files Makefile src/Makefile src/getdns/Makefile src/example/Makefile src/test/Makefile doc/Makefile" ac_config_files="$ac_config_files Makefile src/Makefile src/getdns/Makefile src/example/Makefile src/test/Makefile doc/Makefile"
if test -n "$DOXYGEN" if test -n "$DOXYGEN"

View File

@ -162,6 +162,7 @@ AC_TYPE_UINT32_T
AC_TYPE_UINT64_T AC_TYPE_UINT64_T
AC_TYPE_UINT8_T AC_TYPE_UINT8_T
# libevent extension
have_libevent=1 have_libevent=1
EXTENSION_LIBEVENT_OBJ="extension/libevent.lo" EXTENSION_LIBEVENT_OBJ="extension/libevent.lo"
AC_SEARCH_LIBS([event_loop], AC_SEARCH_LIBS([event_loop],
@ -181,6 +182,19 @@ AC_SEARCH_LIBS([event_loop],
AC_SUBST(have_libevent) AC_SUBST(have_libevent)
AC_SUBST(EXTENSION_LIBEVENT_OBJ) AC_SUBST(EXTENSION_LIBEVENT_OBJ)
# libuv extension
have_libuv=1
EXTENSION_LIBUV_OBJ="extension/libuv.lo"
AC_SEARCH_LIBS([uv_run],
[uv],
[AC_DEFINE([HAVE_LIBUV], [1], [Define to 1 to enable the libuv extension])],
[have_libuv=0]
[EXTENSION_LIBUV_OBJ=""])
AC_SUBST(have_libuv)
AC_SUBST(EXTENSION_LIBUV_OBJ)
AC_CONFIG_FILES([Makefile src/Makefile src/getdns/Makefile src/example/Makefile src/test/Makefile doc/Makefile]) AC_CONFIG_FILES([Makefile src/Makefile src/getdns/Makefile src/example/Makefile src/test/Makefile doc/Makefile])
if [ test -n "$DOXYGEN" ] if [ test -n "$DOXYGEN" ]
then AC_CONFIG_FILES([src/Doxyfile]) then AC_CONFIG_FILES([src/Doxyfile])

View File

@ -33,10 +33,11 @@ CC=gcc
CFLAGS=@CFLAGS@ -Wall -I$(srcdir)/ -I/usr/local/include -std=c99 CFLAGS=@CFLAGS@ -Wall -I$(srcdir)/ -I/usr/local/include -std=c99
LDFLAGS=@LDFLAGS@ @LIBS@ LDFLAGS=@LDFLAGS@ @LIBS@
EXTENSION_LIBEVENT_OBJ=@EXTENSION_LIBEVENT_OBJ@ EXTENSION_LIBEVENT_OBJ=@EXTENSION_LIBEVENT_OBJ@
EXTENSION_LIBUV_OBJ=@EXTENSION_LIBUV_OBJ@
GETDNS_OBJ=sync.lo context.lo list.lo dict.lo convert.lo general.lo \ GETDNS_OBJ=sync.lo context.lo list.lo dict.lo convert.lo general.lo \
hostname.lo service.lo request-internal.lo validate_dnssec.lo \ hostname.lo service.lo request-internal.lo validate_dnssec.lo \
util-internal.lo getdns_error.lo rr-dict.lo validation-chain.lo \ util-internal.lo getdns_error.lo rr-dict.lo validation-chain.lo \
$(EXTENSION_LIBEVENT_OBJ) $(EXTENSION_LIBEVENT_OBJ) $(EXTENSION_LIBUV_OBJ)
.SUFFIXES: .c .o .a .lo .h .SUFFIXES: .c .o .a .lo .h
@ -55,6 +56,7 @@ install: libgetdns.la
$(INSTALL) -m 755 -d $(DESTDIR)$(includedir)/getdns $(INSTALL) -m 755 -d $(DESTDIR)$(includedir)/getdns
$(INSTALL) -m 644 $(srcdir)/getdns/getdns.h $(DESTDIR)$(includedir)/getdns/getdns.h $(INSTALL) -m 644 $(srcdir)/getdns/getdns.h $(DESTDIR)$(includedir)/getdns/getdns.h
if test $(have_libevent) = 1 ; then $(INSTALL) -m 644 $(srcdir)/getdns/getdns_ext_libevent.h $(DESTDIR)$(includedir)/getdns/ ; fi if test $(have_libevent) = 1 ; then $(INSTALL) -m 644 $(srcdir)/getdns/getdns_ext_libevent.h $(DESTDIR)$(includedir)/getdns/ ; fi
if test $(have_libuv) = 1 ; then $(INSTALL) -m 644 $(srcdir)/getdns/getdns_ext_libuv.h $(DESTDIR)$(includedir)/getdns/ ; fi
$(INSTALL) -m 755 -d $(DESTDIR)$(libdir) $(INSTALL) -m 755 -d $(DESTDIR)$(libdir)
$(LIBTOOL) --mode=install cp libgetdns.la $(DESTDIR)$(libdir) $(LIBTOOL) --mode=install cp libgetdns.la $(DESTDIR)$(libdir)
$(LIBTOOL) --mode=finish $(DESTDIR)$(libdir) $(LIBTOOL) --mode=finish $(DESTDIR)$(libdir)

View File

@ -27,6 +27,9 @@
/* Define to 1 if you have the `unbound' library (-lunbound). */ /* Define to 1 if you have the `unbound' library (-lunbound). */
#undef HAVE_LIBUNBOUND #undef HAVE_LIBUNBOUND
/* Define to 1 to enable the libuv extension */
#undef HAVE_LIBUV
/* Define to 1 if you have the <memory.h> header file. */ /* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H #undef HAVE_MEMORY_H

143
src/extension/libuv.c Normal file
View File

@ -0,0 +1,143 @@
/**
* \file
* \brief Public interfaces to getdns, include in your application to use getdns API.
*
* This source was taken from the original pseudo-implementation by
* Paul Hoffman.
*/
/*
* Copyright (c) 2013, NLNet Labs, Versign, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <getdns/getdns_ext_libevent.h>
#include "config.h"
#include "context.h"
#include <sys/time.h>
#include <stdio.h>
#include <uv.h>
#define RETURN_IF_NULL(ptr, code) if(ptr == NULL) return code;
/* extension info */
struct getdns_libuv_data {
uv_loop_t* loop;
uv_poll_t* poll_handle;
};
/* lib event callbacks */
static void
getdns_libuv_cb(uv_poll_t* handle, int status, int events) {
struct getdns_context* context = (struct getdns_context*) handle->data;
getdns_context_process_async(context);
}
static void
getdns_libuv_timeout_cb(uv_timer_t* handle, int status) {
getdns_timeout_data_t* timeout_data = (getdns_timeout_data_t*) handle->data;
timeout_data->callback(timeout_data->userarg);
}
static void
getdns_libuv_close_cb(uv_handle_t* handle) {
if (handle) {
free(handle);
}
}
/* getdns extension functions */
static getdns_return_t
getdns_libuv_cleanup(struct getdns_context* context, void* data) {
struct getdns_libuv_data *uv_data = (struct getdns_libuv_data*) data;
uv_poll_stop(uv_data->poll_handle);
uv_close((uv_handle_t*) uv_data->poll_handle, getdns_libuv_close_cb);
/* handle itself gets cleaned up in close_cb */
free(uv_data);
return GETDNS_RETURN_GOOD;
}
static getdns_return_t
getdns_libuv_schedule_timeout(struct getdns_context* context,
void* eventloop_data, uint16_t timeout,
getdns_timeout_data_t* timeout_data,
void** eventloop_timer) {
uv_timer_t *timer;
struct getdns_libuv_data* uv_data = (struct getdns_libuv_data*) eventloop_data;
timer = (uv_timer_t*) malloc(sizeof(uv_timer_t));
timer->data = timeout_data;
uv_timer_init(uv_data->loop, timer);
uv_timer_start(timer, getdns_libuv_timeout_cb, timeout, 0);
*eventloop_timer = timer;
return GETDNS_RETURN_GOOD;
}
static getdns_return_t
getdns_libuv_clear_timeout(struct getdns_context* context,
void* eventloop_data, void** eventloop_timer) {
uv_timer_t* timer = (uv_timer_t*) eventloop_timer;
uv_timer_stop(timer);
uv_close((uv_handle_t*) timer, getdns_libuv_close_cb);
return GETDNS_RETURN_GOOD;
}
static getdns_eventloop_extension LIBUV_EXT = {
getdns_libuv_cleanup,
getdns_libuv_schedule_timeout,
getdns_libuv_clear_timeout
};
/*
* getdns_extension_set_libuv_loop
*
*/
getdns_return_t
getdns_extension_set_libuv_loop(struct getdns_context *context,
struct uv_loop_s *uv_loop)
{
RETURN_IF_NULL(context, GETDNS_RETURN_INVALID_PARAMETER);
RETURN_IF_NULL(uv_loop, GETDNS_RETURN_INVALID_PARAMETER);
/* TODO: cleanup current extension base */
getdns_return_t r = getdns_extension_detach_eventloop(context);
if (r != GETDNS_RETURN_GOOD) {
return r;
}
struct getdns_libuv_data* uv_data = (struct getdns_libuv_data*) malloc(sizeof(struct getdns_libuv_data));
if (!uv_data) {
return GETDNS_RETURN_MEMORY_ERROR;
}
int fd = getdns_context_fd(context);
uv_data->poll_handle = (uv_poll_t*) malloc(sizeof(uv_poll_t));
uv_poll_init(uv_loop, uv_data->poll_handle, fd);
uv_data->poll_handle->data = context;
uv_data->loop = uv_loop;
uv_poll_start(uv_data->poll_handle, UV_READABLE, getdns_libuv_cb);
return getdns_extension_set_eventloop(context, &LIBUV_EXT, uv_data);
} /* getdns_extension_set_libuv_loop */

View File

@ -0,0 +1,55 @@
/**
* \file
* \brief Public interfaces to getdns, include in your application to use getdns API.
*
* This source was taken from the original pseudo-implementation by
* Paul Hoffman.
*/
/*
* Copyright (c) 2013, NLNet Labs, Versign, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef GETDNS_EXT_LIBUV_H
#define GETDNS_EXT_LIBUV_H
#ifdef __cplusplus
extern "C" {
#endif
#include <getdns/getdns.h>
struct uv_loop_s;
/* For libevent, which we are using for these examples */
getdns_return_t
getdns_extension_set_libuv_loop(struct getdns_context *context,
struct uv_loop_s *uv_loop);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -6,7 +6,6 @@
#include <unistd.h> #include <unistd.h>
#include <check.h> #include <check.h>
#include <getdns/getdns.h> #include <getdns/getdns.h>
#include "check_getdns_libevent.h"
#include "check_getdns_common.h" #include "check_getdns_common.h"
#include "check_getdns_general.h" #include "check_getdns_general.h"
#include "check_getdns_general_sync.h" #include "check_getdns_general_sync.h"

View File

@ -31,7 +31,7 @@
* expect: GETDNS_RETURN_INVALID_PARAMETER * expect: GETDNS_RETURN_INVALID_PARAMETER
*/ */
struct getdns_context *context = NULL; \ struct getdns_context *context = NULL; \
struct event_base *event_base = NULL; \ void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -53,7 +53,7 @@
* expect: GETDNS_RETURN_BAD_DOMAIN_NAME * expect: GETDNS_RETURN_BAD_DOMAIN_NAME
*/ */
struct getdns_context *context = NULL; \ struct getdns_context *context = NULL; \
struct event_base *event_base = NULL; \ void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
const char *name = "oh.my.gosh.and.for.petes.sake.are.you.fricking.crazy.man.because.this.spectacular.and.elaborately.thought.out.domain.name.of.very.significant.length.is.just.too.darn.long.because.you.know.the rfc.states.that.two.hundred.fifty.five.characters.is.the.max.com"; const char *name = "oh.my.gosh.and.for.petes.sake.are.you.fricking.crazy.man.because.this.spectacular.and.elaborately.thought.out.domain.name.of.very.significant.length.is.just.too.darn.long.because.you.know.the rfc.states.that.two.hundred.fifty.five.characters.is.the.max.com";
@ -76,7 +76,7 @@
* expect: GETDNS_RETURN_BAD_DOMAIN_NAME * expect: GETDNS_RETURN_BAD_DOMAIN_NAME
*/ */
struct getdns_context *context = NULL; \ struct getdns_context *context = NULL; \
struct event_base *event_base = NULL; \ void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
const char *name = "this.domain.hasalabelwhichexceedsthemaximumdnslabelsizeofsixtythreecharacters.com"; const char *name = "this.domain.hasalabelwhichexceedsthemaximumdnslabelsizeofsixtythreecharacters.com";
@ -99,7 +99,7 @@
* expect: GETDNS_RETURN_INVALID_PARAMETER * expect: GETDNS_RETURN_INVALID_PARAMETER
*/ */
struct getdns_context *context = NULL; \ struct getdns_context *context = NULL; \
struct event_base *event_base = NULL; \ void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -124,7 +124,7 @@
*/ */
void verify_getdns_address_6(struct extracted_response *ex_response); void verify_getdns_address_6(struct extracted_response *ex_response);
struct getdns_context *context = NULL; \ struct getdns_context *context = NULL; \
struct event_base *event_base = NULL; \ void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -158,7 +158,7 @@
*/ */
void verify_getdns_address_7(struct extracted_response *ex_response); void verify_getdns_address_7(struct extracted_response *ex_response);
struct getdns_context *context = NULL; \ struct getdns_context *context = NULL; \
struct event_base *event_base = NULL; \ void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -189,7 +189,7 @@
*/ */
void verify_getdns_address_8(struct extracted_response *ex_response); void verify_getdns_address_8(struct extracted_response *ex_response);
struct getdns_context *context = NULL; \ struct getdns_context *context = NULL; \
struct event_base *event_base = NULL; \ void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);

View File

@ -30,7 +30,7 @@
*/ */
void verify_getdns_cancel_callback(struct extracted_response *ex_response); void verify_getdns_cancel_callback(struct extracted_response *ex_response);
struct getdns_context *context = NULL; struct getdns_context *context = NULL;
struct event_base *event_base = NULL; void* eventloop = NULL;
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
callback_called = 0; /* Initialize counter */ callback_called = 0; /* Initialize counter */
@ -61,7 +61,7 @@
*/ */
void verify_getdns_cancel_callback(struct extracted_response *ex_response); void verify_getdns_cancel_callback(struct extracted_response *ex_response);
struct getdns_context *context = NULL; struct getdns_context *context = NULL;
struct event_base *event_base = NULL; void* eventloop = NULL;
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
callback_called = 0; /* Initialize counter */ callback_called = 0; /* Initialize counter */
@ -105,7 +105,7 @@
void *userarg, void *userarg,
getdns_transaction_t transaction_id); getdns_transaction_t transaction_id);
struct getdns_context *context = NULL; struct getdns_context *context = NULL;
struct event_base *event_base = NULL; void* eventloop = NULL;
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
getdns_transaction_t transaction_id_array[10] = {}; getdns_transaction_t transaction_id_array[10] = {};
int i; int i;
@ -184,7 +184,7 @@
void *userarg, void *userarg,
getdns_transaction_t transaction_id); getdns_transaction_t transaction_id);
struct getdns_context *context = NULL; struct getdns_context *context = NULL;
struct event_base *event_base = NULL; void* eventloop = NULL;
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
getdns_transaction_t transaction_id_array[10] = {}; getdns_transaction_t transaction_id_array[10] = {};
int i; int i;
@ -264,7 +264,7 @@
void *userarg, void *userarg,
getdns_transaction_t transaction_id); getdns_transaction_t transaction_id);
struct getdns_context *context = NULL; struct getdns_context *context = NULL;
struct event_base *event_base = NULL; void* eventloop = NULL;
struct getdns_bindata address_type = { 5, (void *)"IPv4" }; struct getdns_bindata address_type = { 5, (void *)"IPv4" };
struct getdns_bindata address_data = { 4, (void *)"\x08\x08\x08\x08" }; struct getdns_bindata address_data = { 4, (void *)"\x08\x08\x08\x08" };
struct getdns_dict *address = NULL; struct getdns_dict *address = NULL;
@ -353,7 +353,7 @@
void *userarg, void *userarg,
getdns_transaction_t transaction_id); getdns_transaction_t transaction_id);
struct getdns_context *context = NULL; struct getdns_context *context = NULL;
struct event_base *event_base = NULL; void* eventloop = NULL;
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
getdns_transaction_t transaction_id_array[10] = {}; getdns_transaction_t transaction_id_array[10] = {};
int i; int i;

View File

@ -5,7 +5,15 @@
#include <inttypes.h> #include <inttypes.h>
#include <check.h> #include <check.h>
#include <getdns/getdns.h> #include <getdns/getdns.h>
#include "config.h"
#if HAVE_LIBEVENT
#include "check_getdns_libevent.h"
#include <getdns/getdns_ext_libevent.h> #include <getdns/getdns_ext_libevent.h>
#endif
#if HAVE_LIBUV
#include <getdns/getdns_ext_libuv.h>
#include <uv.h>
#endif
#include "check_getdns_common.h" #include "check_getdns_common.h"
#include <unistd.h> #include <unistd.h>
#include <sys/time.h> #include <sys/time.h>
@ -292,22 +300,29 @@ void update_callbackfn(struct getdns_context *context,
changed_item, expected_changed_item); changed_item, expected_changed_item);
} }
#define NO_LOOP 0
#define LIBEVENT_LOOP 1
#define LIBUV_LOOP 2
static int get_event_loop_type() { static int get_event_loop_type() {
int result = 0; int result = 0;
char* loop = getenv("GETDNS_EVLOOP"); char* loop = getenv("GETDNS_EVLOOP");
if (loop && strcmp("none", loop) == 0) { #if HAVE_LIBEVENT
result = 1; if (loop && strcmp("libevent", loop) == 0) {
result = LIBEVENT_LOOP;
} }
#endif
#if HAVE_LIBUV
if (loop && strcmp("uv", loop) == 0) {
result = LIBUV_LOOP;
}
#endif
return result; return result;
} }
void run_event_loop(struct getdns_context* context, struct event_base* base) { void run_event_loop(struct getdns_context* context, void* eventloop) {
int event_loop_type = get_event_loop_type(); int event_loop_type = get_event_loop_type();
if (event_loop_type == 0) { if (event_loop_type == NO_LOOP) {
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; struct timeval tv;
while (getdns_context_get_num_pending_requests(context, &tv) > 0) { while (getdns_context_get_num_pending_requests(context, &tv) > 0) {
int fd = getdns_context_fd(context); int fd = getdns_context_fd(context);
@ -318,11 +333,28 @@ void run_event_loop(struct getdns_context* context, struct event_base* base) {
getdns_context_process_async(context); getdns_context_process_async(context);
} }
} }
#if HAVE_LIBEVENT
else if (event_loop_type == LIBEVENT_LOOP) {
struct event_base* base = (struct event_base*) eventloop;
while (getdns_context_get_num_pending_requests(context, NULL) > 0) {
event_base_loop(base, EVLOOP_ONCE);
}
}
#endif
#if HAVE_LIBUV
else if (event_loop_type == LIBUV_LOOP) {
uv_loop_t* loop = (uv_loop_t*) eventloop;
while (getdns_context_get_num_pending_requests(context, NULL) > 0) {
uv_run(loop, UV_RUN_ONCE);
}
}
#endif
} }
struct event_base* create_event_base(struct getdns_context* context) { void* create_event_base(struct getdns_context* context) {
int event_loop_type = get_event_loop_type(); int event_loop_type = get_event_loop_type();
if (event_loop_type == 0) { #if HAVE_LIBEVENT
if (event_loop_type == LIBEVENT_LOOP) {
struct event_base* result = event_base_new(); struct event_base* result = event_base_new();
ck_assert_msg(result != NULL, "Event base creation failed"); ck_assert_msg(result != NULL, "Event base creation failed");
ASSERT_RC(getdns_extension_set_libevent_base(context, result), ASSERT_RC(getdns_extension_set_libevent_base(context, result),
@ -330,5 +362,16 @@ struct event_base* create_event_base(struct getdns_context* context) {
"Return code from getdns_extension_set_libevent_base()"); "Return code from getdns_extension_set_libevent_base()");
return result; return result;
} }
#endif
#if HAVE_LIBUV
if (event_loop_type == LIBUV_LOOP) {
uv_loop_t* result = uv_default_loop();
ck_assert_msg(result != NULL, "UV loop creation failed");
ASSERT_RC(getdns_extension_set_libuv_loop(context, result),
GETDNS_RETURN_GOOD,
"Return code from getdns_extension_set_libuv_loop()");
return result;
}
#endif
return NULL; return NULL;
} }

View File

@ -1,7 +1,7 @@
#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
@ -66,12 +66,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 event_base = create_event_base(context); #define EVENT_BASE_CREATE eventloop = create_event_base(context);
/* /*
* The RUN_EVENT_LOOP macro calls the event loop. * The RUN_EVENT_LOOP macro calls the event loop.
*/ */
#define RUN_EVENT_LOOP run_event_loop(context, event_base); #define RUN_EVENT_LOOP run_event_loop(context, eventloop);
/* /*
* The LIST_CREATE macro simply creates a * The LIST_CREATE macro simply creates a
@ -180,8 +180,8 @@
uint16_t changed_item); uint16_t changed_item);
/* run the event loop */ /* run the event loop */
void run_event_loop(struct getdns_context *context, struct event_base* event_base); void run_event_loop(struct getdns_context *context, void* eventloop);
struct event_base* create_event_base(struct getdns_context* context); void* create_event_base(struct getdns_context* context);
#endif #endif

View File

@ -41,7 +41,7 @@
*/ */
void verify_getdns_context_destroy(struct extracted_response *ex_response); void verify_getdns_context_destroy(struct extracted_response *ex_response);
struct getdns_context *context = NULL; struct getdns_context *context = NULL;
struct event_base *event_base = NULL; void* eventloop = NULL;
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
callback_called = 0; /* Initialize counter */ callback_called = 0; /* Initialize counter */
@ -68,7 +68,7 @@
*/ */
void verify_getdns_context_destroy(struct extracted_response *ex_response); void verify_getdns_context_destroy(struct extracted_response *ex_response);
struct getdns_context *context = NULL; struct getdns_context *context = NULL;
struct event_base *event_base = NULL; void* eventloop = NULL;
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
callback_called = 0; /* Initialize counter */ callback_called = 0; /* Initialize counter */
@ -95,7 +95,7 @@
*/ */
void verify_getdns_context_destroy(struct extracted_response *ex_response); void verify_getdns_context_destroy(struct extracted_response *ex_response);
struct getdns_context *context = NULL; struct getdns_context *context = NULL;
struct event_base *event_base = NULL; void* eventloop = NULL;
struct getdns_bindata address_type = { 5, (void *)"IPv4" }; struct getdns_bindata address_type = { 5, (void *)"IPv4" };
struct getdns_bindata address_data = { 4, (void *)"\x08\x08\x08\x08" }; struct getdns_bindata address_data = { 4, (void *)"\x08\x08\x08\x08" };
struct getdns_dict *address = NULL; struct getdns_dict *address = NULL;
@ -132,7 +132,7 @@
*/ */
void verify_getdns_context_destroy(struct extracted_response *ex_response); void verify_getdns_context_destroy(struct extracted_response *ex_response);
struct getdns_context *context = NULL; struct getdns_context *context = NULL;
struct event_base *event_base = NULL; void* eventloop = NULL;
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
callback_called = 0; /* Initialize counter */ callback_called = 0; /* Initialize counter */

View File

@ -31,7 +31,7 @@
* expect: GETDNS_RETURN_INVALID_PARAMETER * expect: GETDNS_RETURN_INVALID_PARAMETER
*/ */
struct getdns_context *context = NULL; \ struct getdns_context *context = NULL; \
struct event_base *event_base = NULL; \ void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -53,7 +53,7 @@
* expect: GETDNS_RETURN_BAD_DOMAIN_NAME * expect: GETDNS_RETURN_BAD_DOMAIN_NAME
*/ */
struct getdns_context *context = NULL; \ struct getdns_context *context = NULL; \
struct event_base *event_base = NULL; \ void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
const char *name = "oh.my.gosh.and.for.petes.sake.are.you.fricking.crazy.man.because.this.spectacular.and.elaborately.thought.out.domain.name.of.very.significant.length.is.just.too.darn.long.because.you.know.the rfc.states.that.two.hundred.fifty.five.characters.is.the.max.com"; const char *name = "oh.my.gosh.and.for.petes.sake.are.you.fricking.crazy.man.because.this.spectacular.and.elaborately.thought.out.domain.name.of.very.significant.length.is.just.too.darn.long.because.you.know.the rfc.states.that.two.hundred.fifty.five.characters.is.the.max.com";
@ -76,7 +76,7 @@
* expect: GETDNS_RETURN_BAD_DOMAIN_NAME * expect: GETDNS_RETURN_BAD_DOMAIN_NAME
*/ */
struct getdns_context *context = NULL; \ struct getdns_context *context = NULL; \
struct event_base *event_base = NULL; \ void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
const char *name = "this.domain.hasalabelwhichexceedsthemaximumdnslabelsizeofsixtythreecharacters.com"; const char *name = "this.domain.hasalabelwhichexceedsthemaximumdnslabelsizeofsixtythreecharacters.com";
@ -99,7 +99,7 @@
* expect: GETDNS_RETURN_INVALID_PARAMETER * expect: GETDNS_RETURN_INVALID_PARAMETER
*/ */
struct getdns_context *context = NULL; \ struct getdns_context *context = NULL; \
struct event_base *event_base = NULL; \ void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -126,7 +126,7 @@
*/ */
void verify_getdns_general_6(struct extracted_response *ex_response); void verify_getdns_general_6(struct extracted_response *ex_response);
struct getdns_context *context = NULL; \ struct getdns_context *context = NULL; \
struct event_base *event_base = NULL; \ void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -159,7 +159,7 @@
*/ */
void verify_getdns_general_7(struct extracted_response *ex_response); void verify_getdns_general_7(struct extracted_response *ex_response);
struct getdns_context *context = NULL; \ struct getdns_context *context = NULL; \
struct event_base *event_base = NULL; \ void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -193,7 +193,7 @@
*/ */
void verify_getdns_general_8(struct extracted_response *ex_response); void verify_getdns_general_8(struct extracted_response *ex_response);
struct getdns_context *context = NULL; \ struct getdns_context *context = NULL; \
struct event_base *event_base = NULL; \ void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -227,7 +227,7 @@
*/ */
void verify_getdns_general_9(struct extracted_response *ex_response); void verify_getdns_general_9(struct extracted_response *ex_response);
struct getdns_context *context = NULL; \ struct getdns_context *context = NULL; \
struct event_base *event_base = NULL; \ void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -262,7 +262,7 @@
*/ */
void verify_getdns_general_10(struct extracted_response *ex_response); void verify_getdns_general_10(struct extracted_response *ex_response);
struct getdns_context *context = NULL; \ struct getdns_context *context = NULL; \
struct event_base *event_base = NULL; \ void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
const char *name = "thisdomainsurelydoesntexist.com"; const char *name = "thisdomainsurelydoesntexist.com";
@ -297,7 +297,7 @@
*/ */
void verify_getdns_general_11(struct extracted_response *ex_response); void verify_getdns_general_11(struct extracted_response *ex_response);
struct getdns_context *context = NULL; \ struct getdns_context *context = NULL; \
struct event_base *event_base = NULL; \ void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -331,7 +331,7 @@
*/ */
void verify_getdns_general_12(struct extracted_response *ex_response); void verify_getdns_general_12(struct extracted_response *ex_response);
struct getdns_context *context = NULL; \ struct getdns_context *context = NULL; \
struct event_base *event_base = NULL; \ void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -360,7 +360,7 @@
* expect: GETDNS_RETURN_BAD_DOMAIN_NAME * expect: GETDNS_RETURN_BAD_DOMAIN_NAME
*/ */
struct getdns_context *context = NULL; \ struct getdns_context *context = NULL; \
struct event_base *event_base = NULL; \ void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -383,7 +383,7 @@
* expect: GETDNS_RETURN_BAD_DOMAIN_NAME * expect: GETDNS_RETURN_BAD_DOMAIN_NAME
*/ */
struct getdns_context *context = NULL; \ struct getdns_context *context = NULL; \
struct event_base *event_base = NULL; \ void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);

View File

@ -42,7 +42,7 @@
* expect: GETDNS_RETURN_INVALID_PARAMETER * expect: GETDNS_RETURN_INVALID_PARAMETER
*/ */
struct getdns_context *context = NULL; struct getdns_context *context = NULL;
struct event_base *event_base = NULL; void* eventloop = NULL;
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -65,7 +65,7 @@
*/ */
struct getdns_context *context = NULL; struct getdns_context *context = NULL;
struct getdns_dict *address = NULL; struct getdns_dict *address = NULL;
struct event_base *event_base = NULL; void* eventloop = NULL;
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -91,7 +91,7 @@
struct getdns_context *context = NULL; struct getdns_context *context = NULL;
struct getdns_dict *address = NULL; struct getdns_dict *address = NULL;
struct getdns_bindata address_type = { 5, (void *) "IPv4" }; struct getdns_bindata address_type = { 5, (void *) "IPv4" };
struct event_base *event_base = NULL; void* eventloop = NULL;
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -123,7 +123,7 @@
struct getdns_context *context = NULL; struct getdns_context *context = NULL;
struct getdns_dict *address = NULL; struct getdns_dict *address = NULL;
struct getdns_bindata address_data = { 4, (void *)"\x08\x08\x08\x08" }; struct getdns_bindata address_data = { 4, (void *)"\x08\x08\x08\x08" };
struct event_base *event_base = NULL; void* eventloop = NULL;
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -156,7 +156,7 @@
*/ */
struct getdns_context *context = NULL; struct getdns_context *context = NULL;
struct getdns_dict *address = NULL; struct getdns_dict *address = NULL;
struct event_base *event_base = NULL; void* eventloop = NULL;
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -190,7 +190,7 @@
struct getdns_dict *address = NULL; struct getdns_dict *address = NULL;
struct getdns_bindata address_type = { 5, (void *)"IPv5" }; struct getdns_bindata address_type = { 5, (void *)"IPv5" };
struct getdns_bindata address_data = { 4, (void *)"\x08\x08\x08\x08" }; struct getdns_bindata address_data = { 4, (void *)"\x08\x08\x08\x08" };
struct event_base *event_base = NULL; void* eventloop = NULL;
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -224,7 +224,7 @@
struct getdns_dict *address = NULL; struct getdns_dict *address = NULL;
struct getdns_bindata address_type = { 5, (void *)"IPv4" }; struct getdns_bindata address_type = { 5, (void *)"IPv4" };
struct getdns_bindata address_data = { 5, (void *)"\x08\x08\x08\x08\x08" }; struct getdns_bindata address_data = { 5, (void *)"\x08\x08\x08\x08\x08" };
struct event_base *event_base = NULL; void* eventloop = NULL;
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -258,7 +258,7 @@
struct getdns_dict *address = NULL; struct getdns_dict *address = NULL;
struct getdns_bindata address_type = { 5, (void *)"IPv4" }; struct getdns_bindata address_type = { 5, (void *)"IPv4" };
struct getdns_bindata address_data = { 4, (void *)"\x08\x08\x08\x08" }; struct getdns_bindata address_data = { 4, (void *)"\x08\x08\x08\x08" };
struct event_base *event_base = NULL; void* eventloop = NULL;
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -293,7 +293,7 @@
struct getdns_dict *address = NULL; struct getdns_dict *address = NULL;
struct getdns_bindata address_type = { 5, (void *)"IPv4" }; struct getdns_bindata address_type = { 5, (void *)"IPv4" };
struct getdns_bindata address_data = { 4, (void *)"\x08\x08\x08\x08" }; struct getdns_bindata address_data = { 4, (void *)"\x08\x08\x08\x08" };
struct event_base *event_base = NULL; void* eventloop = NULL;
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -334,7 +334,7 @@
struct getdns_dict *address = NULL; struct getdns_dict *address = NULL;
struct getdns_bindata address_type = { 5, (void *)"IPv4" }; struct getdns_bindata address_type = { 5, (void *)"IPv4" };
struct getdns_bindata address_data = { 4, (void *)"\x01\x01\x01\x01" }; struct getdns_bindata address_data = { 4, (void *)"\x01\x01\x01\x01" };
struct event_base *event_base = NULL; void* eventloop = NULL;
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -376,7 +376,7 @@
struct getdns_dict *address = NULL; struct getdns_dict *address = NULL;
struct getdns_bindata address_type = { 5, (void *)"IPv6" }; struct getdns_bindata address_type = { 5, (void *)"IPv6" };
struct getdns_bindata address_data = { 16, (void *)"\x26\x07\xf8\xb0\x40\x06\x08\x02\x00\x00\x00\x00\x00\x00\x10\x04" }; struct getdns_bindata address_data = { 16, (void *)"\x26\x07\xf8\xb0\x40\x06\x08\x02\x00\x00\x00\x00\x00\x00\x10\x04" };
struct event_base *event_base = NULL; void* eventloop = NULL;
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);
@ -417,7 +417,7 @@
struct getdns_dict *address = NULL; struct getdns_dict *address = NULL;
struct getdns_bindata address_type = { 5, (void *)"IPv6" }; struct getdns_bindata address_type = { 5, (void *)"IPv6" };
struct getdns_bindata address_data = { 16, (void *)"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" }; struct getdns_bindata address_data = { 16, (void *)"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" };
struct event_base *event_base = NULL; void* eventloop = NULL;
getdns_transaction_t transaction_id = 0; getdns_transaction_t transaction_id = 0;
CONTEXT_CREATE(TRUE); CONTEXT_CREATE(TRUE);

View File

@ -1,4 +1,3 @@
#include "config.h"
#ifdef HAVE_EVENT2_EVENT_H #ifdef HAVE_EVENT2_EVENT_H
#include <event2/event.h> #include <event2/event.h>
#else #else