diff --git a/configure b/configure index 37d48cca..30e9b8fd 100755 --- a/configure +++ b/configure @@ -636,12 +636,15 @@ ac_subst_vars='LTLIBOBJS LIBOBJS TRUST_ANCHOR_FILE EXTENSION_LDFLAGS +CHECK_EV_PROG EXTENSION_LIBEV_EXT_LIBS EXTENSION_LIBEV_LIB have_libev +CHECK_UV_PROG EXTENSION_LIBUV_EXT_LIBS EXTENSION_LIBUV_LIB have_libuv +CHECK_EVENT_PROG EXTENSION_LIBEVENT_EXT_LIBS EXTENSION_LIBEVENT_LIB have_libevent @@ -11173,6 +11176,7 @@ EXTENSION_LDFLAGS=$LDFLAGS have_libevent=1 EXTENSION_LIBEVENT_LIB="libgetdns_ext_event.la" EXTENSION_LIBEVENT_EXT_LIBS="" +CHECK_EVENT_PROG="" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing event_loop" >&5 $as_echo_n "checking for library containing event_loop... " >&6; } if ${ac_cv_search_event_loop+:} false; then : @@ -11238,9 +11242,6 @@ _ACEOF fi done - -$as_echo "#define HAVE_LIBEVENT 1" >>confdefs.h - for ac_header in event2/event.h do : ac_fn_c_check_header_compile "$LINENO" "event2/event.h" "ac_cv_header_event2_event_h" "$ac_includes_default @@ -11255,6 +11256,7 @@ fi done EXTENSION_LIBEVENT_EXT_LIBS="-l$ac_lib" + CHECK_EVENT_PROG=check_getdns_event else have_libevent=0 EXTENSION_LIBEVENT_LIB="" @@ -11265,10 +11267,12 @@ fi + # libuv extension have_libuv=1 EXTENSION_LIBUV_LIB="libgetdns_ext_uv.la" EXTENSION_LIBUV_EXT_LIBS="" +CHECK_UV_PROG="" { $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 : @@ -11322,10 +11326,8 @@ $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 - - EXTENSION_LIBUV_EXT_LIBS="-l$ac_lib" + EXTENSION_LIBUV_EXT_LIBS="-l$ac_lib" + CHECK_UV_PROG=check_getdns_uv else have_libuv=0 EXTENSION_LIBUV_LIB="" @@ -11336,10 +11338,12 @@ fi + # libev extension have_libev=1 EXTENSION_LIBEV_LIB="libgetdns_ext_ev.la" EXTENSION_LIBEV_EXT_LIBS="" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing ev_run" >&5 $as_echo_n "checking for library containing ev_run... " >&6; } if ${ac_cv_search_ev_run+:} false; then : @@ -11393,10 +11397,8 @@ $as_echo "$ac_cv_search_ev_run" >&6; } ac_res=$ac_cv_search_ev_run if test "$ac_res" != no; then : test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" - -$as_echo "#define HAVE_LIBEV 1" >>confdefs.h - - EXTENSION_LIBEV_EXT_LIBS="-l$ac_lib" + EXTENSION_LIBEV_EXT_LIBS="-l$ac_lib" + CHECK_EV_PROG=check_getdns_ev else have_libev=0 EXTENSION_LIBEV_LIB="" @@ -11409,6 +11411,7 @@ fi + LIBS=$getdns_LIBS LDFLAGS=$getdns_LDFLAGS diff --git a/configure.ac b/configure.ac index 3f8f9c76..de30a8c4 100644 --- a/configure.ac +++ b/configure.ac @@ -199,48 +199,54 @@ EXTENSION_LDFLAGS=$LDFLAGS have_libevent=1 EXTENSION_LIBEVENT_LIB="libgetdns_ext_event.la" EXTENSION_LIBEVENT_EXT_LIBS="" +CHECK_EVENT_PROG="" AC_SEARCH_LIBS([event_loop], [event_core event], [AC_CHECK_FUNCS([event_base_new event_base_free])] - [AC_DEFINE([HAVE_LIBEVENT], [1], [Define to 1 to enable the libevent extension])] [AC_CHECK_HEADERS([event2/event.h],,, [AC_INCLUDES_DEFAULT])] - [EXTENSION_LIBEVENT_EXT_LIBS="-l$ac_lib"], + [EXTENSION_LIBEVENT_EXT_LIBS="-l$ac_lib"] + [CHECK_EVENT_PROG=check_getdns_event], [have_libevent=0] [EXTENSION_LIBEVENT_LIB=""]) AC_SUBST(have_libevent) AC_SUBST(EXTENSION_LIBEVENT_LIB) AC_SUBST(EXTENSION_LIBEVENT_EXT_LIBS) +AC_SUBST(CHECK_EVENT_PROG) # libuv extension have_libuv=1 EXTENSION_LIBUV_LIB="libgetdns_ext_uv.la" EXTENSION_LIBUV_EXT_LIBS="" +CHECK_UV_PROG="" AC_SEARCH_LIBS([uv_run], [uv], - [AC_DEFINE([HAVE_LIBUV], [1], [Define to 1 to enable the libuv extension])] - [EXTENSION_LIBUV_EXT_LIBS="-l$ac_lib"], + [EXTENSION_LIBUV_EXT_LIBS="-l$ac_lib"] + [CHECK_UV_PROG=check_getdns_uv], [have_libuv=0] [EXTENSION_LIBUV_LIB=""]) AC_SUBST(have_libuv) AC_SUBST(EXTENSION_LIBUV_LIB) AC_SUBST(EXTENSION_LIBUV_EXT_LIBS) +AC_SUBST(CHECK_UV_PROG) # libev extension have_libev=1 EXTENSION_LIBEV_LIB="libgetdns_ext_ev.la" EXTENSION_LIBEV_EXT_LIBS="" + AC_SEARCH_LIBS([ev_run], [ev], - [AC_DEFINE([HAVE_LIBEV], [1], [Define to 1 to enable the libev extension])] - [EXTENSION_LIBEV_EXT_LIBS="-l$ac_lib"], + [EXTENSION_LIBEV_EXT_LIBS="-l$ac_lib"] + [CHECK_EV_PROG=check_getdns_ev], [have_libev=0] [EXTENSION_LIBEV_LIB=""]) AC_SUBST(have_libev) AC_SUBST(EXTENSION_LIBEV_LIB) AC_SUBST(EXTENSION_LIBEV_EXT_LIBS) +AC_SUBST(CHECK_EV_PROG) AC_SUBST(EXTENSION_LDFLAGS) diff --git a/src/config.h.in b/src/config.h.in index cd6a458f..a37faddc 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -15,12 +15,6 @@ /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H -/* Define to 1 to enable the libev extension */ -#undef HAVE_LIBEV - -/* Define to 1 to enable the libevent extension */ -#undef HAVE_LIBEVENT - /* Define to 1 if you have the `idn' library (-lidn). */ #undef HAVE_LIBIDN @@ -30,9 +24,6 @@ /* Define to 1 if you have the `unbound' library (-lunbound). */ #undef HAVE_LIBUNBOUND -/* Define to 1 to enable the libuv extension */ -#undef HAVE_LIBUV - /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H diff --git a/src/test/Makefile.in b/src/test/Makefile.in index 8c86eca2..fe209368 100644 --- a/src/test/Makefile.in +++ b/src/test/Makefile.in @@ -39,11 +39,23 @@ LIBTOOL = @libtool@ srcdir = @srcdir@ VPATH = @srcdir@ +have_libevent = @have_libevent@ +have_libuv = @have_libuv@ +have_libev = @have_libev@ + +EXTENSION_LIBEVENT_EXT_LIBS=@EXTENSION_LIBEVENT_EXT_LIBS@ +EXTENSION_LIBUV_EXT_LIBS=@EXTENSION_LIBUV_EXT_LIBS@ +EXTENSION_LIBEV_EXT_LIBS=@EXTENSION_LIBEV_EXT_LIBS@ + +CHECK_UV_PROG=@CHECK_UV_PROG@ +CHECK_EVENT_PROG=@CHECK_EVENT_PROG@ +CHECK_EV_PROG=@CHECK_EV_PROG@ + CC=@CC@ CFLAGS=@CFLAGS@ -Wall -I$(srcdir)/ -I$(srcdir)/../ -I/usr/local/include -std=c99 $(cflags) LDFLAGS=@LDFLAGS@ -L. -L.. -L$(srcdir)/../ -L/usr/local/lib LDLIBS=-lgetdns @LIBS@ -lcheck -PROGRAMS=tests_dict tests_list tests_stub_async tests_stub_sync check_getdns tests_dnssec +PROGRAMS=tests_dict tests_list tests_stub_async tests_stub_sync check_getdns tests_dnssec $(CHECK_EV_PROG) $(CHECK_EVENT_PROG) $(CHECK_UV_PROG) .SUFFIXES: .c .o .a .lo .h @@ -69,8 +81,17 @@ tests_stub_sync: tests_stub_sync.o check_getdns_common: check_getdns_common.o $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ check_getdns_common.o -check_getdns: check_getdns.o check_getdns_common.o check_getdns_context_set_timeout.o - $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ check_getdns.o check_getdns_common.o check_getdns_context_set_timeout.o +check_getdns: check_getdns.o check_getdns_common.o check_getdns_context_set_timeout.o check_getdns_selectloop.o + $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ check_getdns.o check_getdns_common.o check_getdns_context_set_timeout.o check_getdns_selectloop.o + +check_getdns_event: check_getdns.o check_getdns_common.o check_getdns_context_set_timeout.o check_getdns_libevent.o + $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -lgetdns_ext_event $(EXTENSION_LIBEVENT_EXT_LIBS) $(LDLIBS) -o $@ check_getdns.o check_getdns_common.o check_getdns_context_set_timeout.o check_getdns_libevent.o + +check_getdns_uv: check_getdns.o check_getdns_common.o check_getdns_context_set_timeout.o check_getdns_libuv.o + $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -lgetdns_ext_uv $(EXTENSION_LIBUV_EXT_LIBS) $(LDLIBS) -o $@ check_getdns.o check_getdns_common.o check_getdns_context_set_timeout.o check_getdns_libuv.o + +check_getdns_ev: 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) -lgetdns_ext_ev $(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 $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -lgetdns_ext_event $(LDLIBS) -o $@ tests_dnssec.o testmessages.o @@ -78,6 +99,9 @@ tests_dnssec: tests_dnssec.o testmessages.o test: all ./check_getdns + if test $(have_libevent) = 1 ; then ./$(CHECK_EVENT_PROG) ; fi + if test $(have_libev) = 1 ; then ./$(CHECK_EV_PROG) ; fi + if test $(have_libuv) = 1 ; then ./$(CHECK_UV_PROG) ; fi @echo "All tests OK" clean: diff --git a/src/test/check_getdns_common.c b/src/test/check_getdns_common.c index d2b20bd2..56d7cc15 100644 --- a/src/test/check_getdns_common.c +++ b/src/test/check_getdns_common.c @@ -32,29 +32,11 @@ #include #include #include "config.h" -#include -#if HAVE_LIBEVENT -#include "check_getdns_libevent.h" -typedef getdns_return_t -(*getdns_extension_set_libevent_loop_fn)(struct getdns_context *context, - struct event_base *this_event_base); -#endif -#if HAVE_LIBUV -#include -#endif -#if HAVE_LIBEV -#include "check_getdns_libev.h" -#endif #include "check_getdns_common.h" +#include "check_getdns_eventloop.h" #include #include -#ifdef __APPLE__ -#define SO_EXT ".dylib" -#else -#define SO_EXT ".so" -#endif - int callback_called = 0; int callback_completed = 0; int callback_canceled = 0; @@ -335,94 +317,10 @@ void update_callbackfn(struct getdns_context *context, changed_item, expected_changed_item); } -#define NO_LOOP 0 -#define LIBEVENT_LOOP 1 -#define LIBUV_LOOP 2 -#define LIBEV_LOOP 3 - -static int get_event_loop_type() { - int result = 0; - char* loop = getenv("GETDNS_EVLOOP"); - if (loop && strcmp("libevent", loop) == 0) { - result = LIBEVENT_LOOP; - } - if (loop && strcmp("libuv", loop) == 0) { - result = LIBUV_LOOP; - } - if (loop && strcmp("libev", loop) == 0) { - result = LIBEV_LOOP; - } - return result; -} - void run_event_loop(struct getdns_context* context, void* eventloop) { - int event_loop_type = get_event_loop_type(); - if (event_loop_type == NO_LOOP) { - 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); - } - } - // #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 - // #if HAVE_LIBEV - // else if (event_loop_type == LIBEV_LOOP) { - // run_libev_event_loop(context, eventloop); - // } - // #endif + run_event_loop_impl(context, eventloop); } void* create_event_base(struct getdns_context* context) { - // int event_loop_type = get_event_loop_type(); - // #if HAVE_LIBEVENT - // if (event_loop_type == LIBEVENT_LOOP) { - // /* load the lib */ - // void* ext_library = dlopen("libgetdns_ext_event" SO_EXT, RTLD_LAZY); - // if (!ext_library) { return NULL; } - // void* ext_setter = dlsym(ext_library,"getdns_extension_set_libevent_base"); - // if (!ext_setter) { return NULL; } - // getdns_extension_set_libevent_loop_fn fn = (getdns_extension_set_libevent_loop_fn) ext_setter; - // struct event_base* result = event_base_new(); - // ck_assert_msg(result != NULL, "Event base creation failed"); - // ASSERT_RC(fn(context, result), - // GETDNS_RETURN_GOOD, - // "Return code from getdns_extension_set_libevent_base()"); - // 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 - // #if HAVE_LIBEV - // if (event_loop_type == LIBEV_LOOP) { - // return create_libev_base(context); - // } - // #endif - return NULL; + return create_eventloop_impl(context); } diff --git a/src/test/check_getdns_common.h b/src/test/check_getdns_common.h index 6144951d..fb94dd14 100644 --- a/src/test/check_getdns_common.h +++ b/src/test/check_getdns_common.h @@ -64,9 +64,9 @@ { \ size_t buflen = MAXLEN; \ char error_string[MAXLEN]; \ - getdns_return_t evaluated_rc = rc; \ + uint32_t evaluated_rc = rc; \ getdns_strerror(evaluated_rc, error_string, buflen); \ - ck_assert_msg(evaluated_rc == expected_rc, \ + ck_assert_msg((uint32_t) evaluated_rc == (uint32_t) expected_rc, \ "%s: expecting %s: %d, but received: %d: %s", \ prefix, #expected_rc, expected_rc, evaluated_rc, error_string); \ } diff --git a/src/test/check_getdns_libev.h b/src/test/check_getdns_eventloop.h similarity index 89% rename from src/test/check_getdns_libev.h rename to src/test/check_getdns_eventloop.h index 392fb349..9a370016 100644 --- a/src/test/check_getdns_libev.h +++ b/src/test/check_getdns_eventloop.h @@ -34,15 +34,13 @@ */ /* this is used to prevent header conflicts with libevent and libev */ -#ifndef _check_getdns_libev_h_ -#define _check_getdns_libev_h_ +#ifndef _check_getdns_eventloop_h_ +#define _check_getdns_eventloop_h_ #include "config.h" -#if HAVE_LIBEV struct getdns_context* context; -void run_libev_event_loop(struct getdns_context* context, void* eventloop); -void* create_libev_base(struct getdns_context* context); -#endif +void run_event_loop_impl(struct getdns_context* context, void* eventloop); +void* create_eventloop_impl(struct getdns_context* context); #endif diff --git a/src/test/check_getdns_libev.c b/src/test/check_getdns_libev.c index 4cedbc84..6a5b2455 100644 --- a/src/test/check_getdns_libev.c +++ b/src/test/check_getdns_libev.c @@ -33,24 +33,21 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "check_getdns_libev.h" - -#if HAVE_LIBEV +#include "check_getdns_eventloop.h" #include #include #include #include "check_getdns_common.h" -void run_libev_event_loop(struct getdns_context* context, void* eventloop) { +void run_event_loop_impl(struct getdns_context* context, void* eventloop) { struct ev_loop* loop = (struct ev_loop*) eventloop; while (getdns_context_get_num_pending_requests(context, NULL) > 0) { ev_run(loop, EVRUN_ONCE); } } - -void* create_libev_base(struct getdns_context* context) { +void* create_eventloop_impl(struct getdns_context* context) { struct ev_loop* result = ev_default_loop(0); ck_assert_msg(result != NULL, "EV loop creation failed"); ASSERT_RC(getdns_extension_set_libev_loop(context, result), @@ -58,5 +55,3 @@ void* create_libev_base(struct getdns_context* context) { "Return code from getdns_extension_set_libev_loop()"); return result; } - -#endif diff --git a/src/test/check_getdns_libevent.c b/src/test/check_getdns_libevent.c new file mode 100644 index 00000000..d2d39c03 --- /dev/null +++ b/src/test/check_getdns_libevent.c @@ -0,0 +1,57 @@ +/** + * \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 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 "check_getdns_eventloop.h" + +#include +#include "check_getdns_libevent.h" +#include +#include "check_getdns_common.h" + +void run_event_loop_impl(struct getdns_context* context, void* eventloop) { + struct event_base* base = (struct event_base*) eventloop; + while (getdns_context_get_num_pending_requests(context, NULL) > 0) { + event_base_loop(base, EVLOOP_ONCE); + } +} + +void* create_eventloop_impl(struct getdns_context* context) { + 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; +} diff --git a/src/test/check_getdns_libuv.c b/src/test/check_getdns_libuv.c new file mode 100644 index 00000000..c1ffcf77 --- /dev/null +++ b/src/test/check_getdns_libuv.c @@ -0,0 +1,58 @@ +/** + * \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 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 "check_getdns_eventloop.h" + +#include +#include +#include +#include "check_getdns_common.h" + +void run_event_loop_impl(struct getdns_context* context, void* eventloop) { + uv_loop_t* loop = (uv_loop_t*) eventloop; + while (getdns_context_get_num_pending_requests(context, NULL) > 0) { + uv_run(loop, UV_RUN_ONCE); + } +} + + +void* create_eventloop_impl(struct getdns_context* context) { + 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; +} diff --git a/src/test/check_getdns_selectloop.c b/src/test/check_getdns_selectloop.c new file mode 100644 index 00000000..d3090bac --- /dev/null +++ b/src/test/check_getdns_selectloop.c @@ -0,0 +1,54 @@ +/** + * \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 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 "check_getdns_eventloop.h" +#include + +void run_event_loop_impl(struct getdns_context* context, void* eventloop) { + 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); + } +} + + +void* create_eventloop_impl(struct getdns_context* context) { + return NULL; +}