Merge pull request #259 from wtoorop/devel/fixed_eventloop

Devel/fixed eventloop
This commit is contained in:
Melinda Shore 2017-02-15 10:25:45 -09:00 committed by GitHub
commit c72d74a0fa
14 changed files with 2018 additions and 241 deletions

View File

@ -214,6 +214,31 @@ case "$enable_debug_keep_connections_open" in
;; ;;
esac esac
DEFAULT_EVENTLOOP=select_eventloop
AC_CHECK_HEADERS([sys/poll.h poll.h sys/resource.h],,, [AC_INCLUDES_DEFAULT])
AC_CHECK_FUNCS([getrlimit])
AC_ARG_ENABLE(poll-eventloop, AC_HELP_STRING([--disable-poll-eventloop], [Disable default eventloop based on poll (default=enabled if available)]))
case "$enable_poll_eventloop" in
no)
;;
yes|*)
AC_MSG_CHECKING(for poll)
AC_LINK_IFELSE([AC_LANG_PROGRAM([
#ifdef HAVE_SYS_POLL_H
#include <sys/poll.h>
#else
#include <poll.h>
#endif
], [int rc; rc = poll((struct pollfd *)(0), 0, 0);])], [
AC_MSG_RESULT(yes)
AC_DEFINE_UNQUOTED([USE_POLL_DEFAULT_EVENTLOOP], [1], [Define this to enable a default eventloop based on poll().])
DEFAULT_EVENTLOOP=poll_eventloop
],[AC_MSG_RESULT(no)])
;;
esac
AC_SUBST(DEFAULT_EVENTLOOP)
AC_ARG_ENABLE(tcp-fastopen, AC_HELP_STRING([--disable-tcp-fastopen], Disable TCP Fast Open (default=enabled if available)), AC_ARG_ENABLE(tcp-fastopen, AC_HELP_STRING([--disable-tcp-fastopen], Disable TCP Fast Open (default=enabled if available)),
enable_tcp_fastopen="$enableval", enable_tcp_fastopen=yes) enable_tcp_fastopen="$enableval", enable_tcp_fastopen=yes)
if test "x$enable_tcp_fastopen" = xno; then if test "x$enable_tcp_fastopen" = xno; then
@ -1076,8 +1101,6 @@ if test "$ac_cv_func_arc4random" = "no"; then
]) ])
fi fi
AC_DEFINE(USE_MINI_EVENT, 1, [Needed for sync stub resolver functions])
AC_TYPE_SIGNAL AC_TYPE_SIGNAL
case `uname` in case `uname` in

View File

@ -149,16 +149,24 @@ depend:
# Dependencies for the examples # Dependencies for the examples
example-all-functions.lo example-all-functions.o: $(srcdir)/example-all-functions.c $(srcdir)/getdns_libevent.h \ example-all-functions.lo example-all-functions.o: $(srcdir)/example-all-functions.c $(srcdir)/getdns_libevent.h \
../../src/config.h ../../src/getdns/getdns.h \ ../../src/config.h \
$(srcdir)/../../src/getdns/getdns_ext_libevent.h ../../src/getdns/getdns_extra.h ../../src/getdns/getdns.h \
example-reverse.lo example-reverse.o: $(srcdir)/example-reverse.c $(srcdir)/getdns_libevent.h ../../src/config.h \ $(srcdir)/../../src/getdns/getdns_ext_libevent.h \
../../src/getdns/getdns.h $(srcdir)/../../src/getdns/getdns_ext_libevent.h \ ../../src/getdns/getdns_extra.h
example-reverse.lo example-reverse.o: $(srcdir)/example-reverse.c $(srcdir)/getdns_libevent.h \
../../src/config.h \
../../src/getdns/getdns.h \
$(srcdir)/../../src/getdns/getdns_ext_libevent.h \
../../src/getdns/getdns_extra.h ../../src/getdns/getdns_extra.h
example-simple-answers.lo example-simple-answers.o: $(srcdir)/example-simple-answers.c $(srcdir)/getdns_libevent.h \ example-simple-answers.lo example-simple-answers.o: $(srcdir)/example-simple-answers.c $(srcdir)/getdns_libevent.h \
../../src/config.h ../../src/getdns/getdns.h \ ../../src/config.h \
$(srcdir)/../../src/getdns/getdns_ext_libevent.h ../../src/getdns/getdns_extra.h ../../src/getdns/getdns.h \
$(srcdir)/../../src/getdns/getdns_ext_libevent.h \
../../src/getdns/getdns_extra.h
example-synchronous.lo example-synchronous.o: $(srcdir)/example-synchronous.c $(srcdir)/getdns_core_only.h \ example-synchronous.lo example-synchronous.o: $(srcdir)/example-synchronous.c $(srcdir)/getdns_core_only.h \
../../src/getdns/getdns.h ../../src/getdns/getdns.h
example-tree.lo example-tree.o: $(srcdir)/example-tree.c $(srcdir)/getdns_libevent.h ../../src/config.h \ example-tree.lo example-tree.o: $(srcdir)/example-tree.c $(srcdir)/getdns_libevent.h \
../../src/getdns/getdns.h $(srcdir)/../../src/getdns/getdns_ext_libevent.h \ ../../src/config.h \
../../src/getdns/getdns.h \
$(srcdir)/../../src/getdns/getdns_ext_libevent.h \
../../src/getdns/getdns_extra.h ../../src/getdns/getdns_extra.h

View File

@ -65,6 +65,8 @@ EXTENSION_LIBUV_LDFLAGS=@EXTENSION_LIBUV_LDFLAGS@
C99COMPATFLAGS=@C99COMPATFLAGS@ C99COMPATFLAGS=@C99COMPATFLAGS@
DEFAULT_EVENTLOOP_OBJ=@DEFAULT_EVENTLOOP@.lo
GETDNS_OBJ=const-info.lo convert.lo dict.lo dnssec.lo general.lo \ GETDNS_OBJ=const-info.lo convert.lo dict.lo dnssec.lo general.lo \
list.lo request-internal.lo pubkey-pinning.lo rr-dict.lo \ list.lo request-internal.lo pubkey-pinning.lo rr-dict.lo \
rr-iter.lo server.lo stub.lo sync.lo ub_loop.lo util-internal.lo \ rr-iter.lo server.lo stub.lo sync.lo ub_loop.lo util-internal.lo \
@ -81,7 +83,7 @@ UTIL_OBJ=rbtree.lo val_secalgo.lo
JSMN_OBJ=jsmn.lo JSMN_OBJ=jsmn.lo
EXTENSION_OBJ=default_eventloop.lo libevent.lo libev.lo EXTENSION_OBJ=$(DEFAULT_EVENTLOOP_OBJ) libevent.lo libev.lo
NON_C99_OBJS=context.lo libuv.lo NON_C99_OBJS=context.lo libuv.lo
@ -152,8 +154,8 @@ libgetdns_ext_ev.la: libgetdns.la libev.lo
$(LIBTOOL) --tag=CC --mode=link $(CC) -o $@ libev.lo libgetdns.la $(LDFLAGS) $(EXTENSION_LIBEV_LDFLAGS) $(EXTENSION_LIBEV_EXT_LIBS) -rpath $(libdir) -version-info $(libversion) -no-undefined -export-symbols $(srcdir)/extension/libev.symbols $(LIBTOOL) --tag=CC --mode=link $(CC) -o $@ libev.lo libgetdns.la $(LDFLAGS) $(EXTENSION_LIBEV_LDFLAGS) $(EXTENSION_LIBEV_EXT_LIBS) -rpath $(libdir) -version-info $(libversion) -no-undefined -export-symbols $(srcdir)/extension/libev.symbols
libgetdns.la: $(GETDNS_OBJ) version.lo context.lo default_eventloop.lo $(GLDNS_OBJ) $(COMPAT_OBJ) $(UTIL_OBJ) $(JSMN_OBJ) libgetdns.la: $(GETDNS_OBJ) version.lo context.lo $(DEFAULT_EVENTLOOP_OBJ) $(GLDNS_OBJ) $(COMPAT_OBJ) $(UTIL_OBJ) $(JSMN_OBJ)
$(LIBTOOL) --tag=CC --mode=link $(CC) -o $@ $(GETDNS_OBJ) version.lo context.lo default_eventloop.lo $(GLDNS_OBJ) $(COMPAT_OBJ) $(UTIL_OBJ) $(JSMN_OBJ) $(LDFLAGS) -rpath $(libdir) -version-info $(libversion) -no-undefined -export-symbols $(srcdir)/libgetdns.symbols $(LIBTOOL) --tag=CC --mode=link $(CC) -o $@ $(GETDNS_OBJ) version.lo context.lo $(DEFAULT_EVENTLOOP_OBJ) $(GLDNS_OBJ) $(COMPAT_OBJ) $(UTIL_OBJ) $(JSMN_OBJ) $(LDFLAGS) -rpath $(libdir) -version-info $(libversion) -no-undefined -export-symbols $(srcdir)/libgetdns.symbols
test: all test: all
cd test && $(MAKE) $@ cd test && $(MAKE) $@
@ -213,132 +215,236 @@ depend:
FORCE: FORCE:
# Dependencies for gldns, utils, the extensions and compat functions # Dependencies for gldns, utils, the extensions and compat functions
const-info.lo const-info.o: $(srcdir)/const-info.c getdns/getdns.h getdns/getdns_extra.h \ const-info.lo const-info.o: $(srcdir)/const-info.c \
getdns/getdns.h $(srcdir)/const-info.h getdns/getdns.h \
context.lo context.o: $(srcdir)/context.c config.h $(srcdir)/debug.h $(srcdir)/gldns/str2wire.h $(srcdir)/gldns/rrdef.h \ getdns/getdns_extra.h \
$(srcdir)/gldns/wire2str.h $(srcdir)/context.h getdns/getdns.h getdns/getdns_extra.h \ $(srcdir)/const-info.h
getdns/getdns.h $(srcdir)/types-internal.h $(srcdir)/util/rbtree.h \ context.lo context.o: $(srcdir)/context.c \
$(srcdir)/extension/default_eventloop.h config.h getdns/getdns_extra.h $(srcdir)/ub_loop.h \ config.h \
$(srcdir)/debug.h $(srcdir)/gldns/str2wire.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/wire2str.h $(srcdir)/context.h \
getdns/getdns.h \
getdns/getdns_extra.h \
$(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/extension/default_eventloop.h \
$(srcdir)/extension/poll_eventloop.h $(srcdir)/types-internal.h $(srcdir)/util/uthash.h $(srcdir)/ub_loop.h \
$(srcdir)/server.h $(srcdir)/util-internal.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h \ $(srcdir)/server.h $(srcdir)/util-internal.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h \
$(srcdir)/gldns/pkthdr.h $(srcdir)/dnssec.h $(srcdir)/gldns/rrdef.h $(srcdir)/stub.h $(srcdir)/list.h $(srcdir)/dict.h \ $(srcdir)/gldns/pkthdr.h $(srcdir)/dnssec.h $(srcdir)/gldns/rrdef.h $(srcdir)/stub.h $(srcdir)/list.h $(srcdir)/dict.h \
$(srcdir)/pubkey-pinning.h $(srcdir)/pubkey-pinning.h
convert.lo convert.o: $(srcdir)/convert.c config.h getdns/getdns.h getdns/getdns_extra.h \ convert.lo convert.o: $(srcdir)/convert.c \
getdns/getdns.h $(srcdir)/util-internal.h $(srcdir)/context.h $(srcdir)/types-internal.h $(srcdir)/util/rbtree.h \ config.h \
$(srcdir)/extension/default_eventloop.h config.h getdns/getdns_extra.h $(srcdir)/ub_loop.h \ getdns/getdns.h \
getdns/getdns_extra.h \
$(srcdir)/util-internal.h $(srcdir)/context.h $(srcdir)/types-internal.h $(srcdir)/util/rbtree.h \
$(srcdir)/extension/default_eventloop.h $(srcdir)/extension/poll_eventloop.h \
$(srcdir)/types-internal.h $(srcdir)/util/uthash.h $(srcdir)/ub_loop.h $(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/rr-iter.h \
$(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h $(srcdir)/gldns/wire2str.h \
$(srcdir)/gldns/str2wire.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/parseutil.h $(srcdir)/const-info.h $(srcdir)/dict.h \
$(srcdir)/list.h $(srcdir)/jsmn/jsmn.h $(srcdir)/convert.h
dict.lo dict.o: $(srcdir)/dict.c \
config.h \
$(srcdir)/types-internal.h \
getdns/getdns.h \
getdns/getdns_extra.h \
$(srcdir)/util/rbtree.h $(srcdir)/util-internal.h $(srcdir)/context.h $(srcdir)/extension/default_eventloop.h \
$(srcdir)/extension/poll_eventloop.h $(srcdir)/types-internal.h $(srcdir)/util/uthash.h $(srcdir)/ub_loop.h \
$(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h \ $(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h \
$(srcdir)/gldns/wire2str.h $(srcdir)/gldns/str2wire.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/parseutil.h \ $(srcdir)/dict.h $(srcdir)/list.h $(srcdir)/const-info.h $(srcdir)/gldns/wire2str.h
$(srcdir)/const-info.h $(srcdir)/dict.h $(srcdir)/list.h $(srcdir)/jsmn/jsmn.h $(srcdir)/convert.h dnssec.lo dnssec.o: $(srcdir)/dnssec.c \
dict.lo dict.o: $(srcdir)/dict.c config.h $(srcdir)/types-internal.h getdns/getdns.h \ config.h \
getdns/getdns_extra.h getdns/getdns.h $(srcdir)/util/rbtree.h $(srcdir)/util-internal.h \ $(srcdir)/debug.h \
$(srcdir)/context.h $(srcdir)/extension/default_eventloop.h config.h getdns/getdns_extra.h \ getdns/getdns.h \
$(srcdir)/ub_loop.h $(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h \ $(srcdir)/context.h \
$(srcdir)/gldns/pkthdr.h $(srcdir)/dict.h $(srcdir)/list.h $(srcdir)/const-info.h $(srcdir)/gldns/wire2str.h getdns/getdns_extra.h \
dnssec.lo dnssec.o: $(srcdir)/dnssec.c config.h $(srcdir)/debug.h getdns/getdns.h $(srcdir)/context.h \ $(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/extension/default_eventloop.h \
getdns/getdns_extra.h getdns/getdns.h $(srcdir)/types-internal.h $(srcdir)/util/rbtree.h \ $(srcdir)/extension/poll_eventloop.h $(srcdir)/types-internal.h $(srcdir)/util/uthash.h $(srcdir)/ub_loop.h \
$(srcdir)/extension/default_eventloop.h config.h getdns/getdns_extra.h $(srcdir)/ub_loop.h \
$(srcdir)/server.h $(srcdir)/util-internal.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h \ $(srcdir)/server.h $(srcdir)/util-internal.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h \
$(srcdir)/gldns/pkthdr.h $(srcdir)/dnssec.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/str2wire.h $(srcdir)/gldns/rrdef.h \ $(srcdir)/gldns/pkthdr.h $(srcdir)/dnssec.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/str2wire.h $(srcdir)/gldns/rrdef.h \
$(srcdir)/gldns/wire2str.h $(srcdir)/gldns/keyraw.h $(srcdir)/gldns/parseutil.h $(srcdir)/general.h $(srcdir)/dict.h \ $(srcdir)/gldns/wire2str.h $(srcdir)/gldns/keyraw.h $(srcdir)/gldns/parseutil.h $(srcdir)/general.h $(srcdir)/dict.h \
$(srcdir)/list.h $(srcdir)/util/val_secalgo.h $(srcdir)/list.h $(srcdir)/util/val_secalgo.h
general.lo general.o: $(srcdir)/general.c config.h $(srcdir)/general.h getdns/getdns.h $(srcdir)/types-internal.h \ general.lo general.o: $(srcdir)/general.c \
getdns/getdns_extra.h getdns/getdns.h $(srcdir)/util/rbtree.h $(srcdir)/ub_loop.h $(srcdir)/debug.h \ config.h \
$(srcdir)/gldns/wire2str.h $(srcdir)/context.h $(srcdir)/extension/default_eventloop.h config.h \ $(srcdir)/general.h \
getdns/getdns_extra.h $(srcdir)/server.h $(srcdir)/util-internal.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h \ getdns/getdns.h \
$(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h $(srcdir)/dnssec.h $(srcdir)/gldns/rrdef.h $(srcdir)/stub.h $(srcdir)/dict.h \ $(srcdir)/types-internal.h \
$(srcdir)/mdns.h getdns/getdns_extra.h \
list.lo list.o: $(srcdir)/list.c $(srcdir)/types-internal.h getdns/getdns.h getdns/getdns_extra.h \ $(srcdir)/util/rbtree.h $(srcdir)/ub_loop.h $(srcdir)/debug.h $(srcdir)/gldns/wire2str.h $(srcdir)/context.h \
getdns/getdns.h $(srcdir)/util/rbtree.h $(srcdir)/util-internal.h config.h $(srcdir)/context.h \ $(srcdir)/extension/default_eventloop.h $(srcdir)/extension/poll_eventloop.h \
$(srcdir)/extension/default_eventloop.h config.h getdns/getdns_extra.h $(srcdir)/ub_loop.h \ $(srcdir)/types-internal.h $(srcdir)/util/uthash.h $(srcdir)/server.h $(srcdir)/util-internal.h $(srcdir)/rr-iter.h \
$(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h \ $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h $(srcdir)/dnssec.h $(srcdir)/gldns/rrdef.h $(srcdir)/stub.h \
$(srcdir)/list.h $(srcdir)/dict.h $(srcdir)/dict.h $(srcdir)/mdns.h
mdns.lo mdns.o: $(srcdir)/mdns.c config.h $(srcdir)/debug.h $(srcdir)/context.h getdns/getdns.h \ list.lo list.o: $(srcdir)/list.c $(srcdir)/types-internal.h \
getdns/getdns_extra.h getdns/getdns.h $(srcdir)/types-internal.h $(srcdir)/util/rbtree.h \ getdns/getdns.h \
$(srcdir)/extension/default_eventloop.h config.h getdns/getdns_extra.h $(srcdir)/ub_loop.h \ getdns/getdns_extra.h \
$(srcdir)/util/rbtree.h $(srcdir)/util-internal.h \
config.h \
$(srcdir)/context.h $(srcdir)/extension/default_eventloop.h $(srcdir)/extension/poll_eventloop.h \
$(srcdir)/types-internal.h $(srcdir)/util/uthash.h $(srcdir)/ub_loop.h $(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/rr-iter.h \
$(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h $(srcdir)/list.h $(srcdir)/dict.h
mdns.lo mdns.o: $(srcdir)/mdns.c \
config.h \
$(srcdir)/debug.h $(srcdir)/context.h \
getdns/getdns.h \
getdns/getdns_extra.h \
$(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/extension/default_eventloop.h \
$(srcdir)/extension/poll_eventloop.h $(srcdir)/types-internal.h $(srcdir)/util/uthash.h $(srcdir)/ub_loop.h \
$(srcdir)/server.h $(srcdir)/general.h $(srcdir)/gldns/pkthdr.h $(srcdir)/util-internal.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h \ $(srcdir)/server.h $(srcdir)/general.h $(srcdir)/gldns/pkthdr.h $(srcdir)/util-internal.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h \
$(srcdir)/gldns/gbuffer.h $(srcdir)/mdns.h $(srcdir)/gldns/gbuffer.h $(srcdir)/mdns.h
pubkey-pinning.lo pubkey-pinning.o: $(srcdir)/pubkey-pinning.c config.h $(srcdir)/debug.h getdns/getdns.h \ pubkey-pinning.lo pubkey-pinning.o: $(srcdir)/pubkey-pinning.c \
$(srcdir)/context.h getdns/getdns.h getdns/getdns_extra.h $(srcdir)/types-internal.h \ config.h \
$(srcdir)/util/rbtree.h $(srcdir)/extension/default_eventloop.h config.h \ $(srcdir)/debug.h \
getdns/getdns_extra.h $(srcdir)/ub_loop.h $(srcdir)/server.h $(srcdir)/util-internal.h $(srcdir)/rr-iter.h \ getdns/getdns.h \
$(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h $(srcdir)/context.h \
request-internal.lo request-internal.o: $(srcdir)/request-internal.c config.h $(srcdir)/types-internal.h \ getdns/getdns_extra.h \
getdns/getdns.h getdns/getdns_extra.h getdns/getdns.h $(srcdir)/util/rbtree.h \ $(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/extension/default_eventloop.h \
$(srcdir)/util-internal.h $(srcdir)/context.h $(srcdir)/extension/default_eventloop.h config.h \ $(srcdir)/extension/poll_eventloop.h $(srcdir)/types-internal.h $(srcdir)/util/uthash.h $(srcdir)/ub_loop.h \
getdns/getdns_extra.h $(srcdir)/ub_loop.h $(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h \ $(srcdir)/server.h $(srcdir)/util-internal.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h \
$(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/str2wire.h \ $(srcdir)/gldns/pkthdr.h
$(srcdir)/gldns/rrdef.h $(srcdir)/dict.h $(srcdir)/convert.h request-internal.lo request-internal.o: $(srcdir)/request-internal.c \
rr-dict.lo rr-dict.o: $(srcdir)/rr-dict.c $(srcdir)/rr-dict.h config.h getdns/getdns.h $(srcdir)/gldns/gbuffer.h \ config.h \
$(srcdir)/util-internal.h $(srcdir)/context.h getdns/getdns_extra.h getdns/getdns.h \ $(srcdir)/types-internal.h \
$(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/extension/default_eventloop.h config.h \ getdns/getdns.h \
getdns/getdns_extra.h $(srcdir)/ub_loop.h $(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/rr-iter.h \ getdns/getdns_extra.h \
$(srcdir)/gldns/pkthdr.h $(srcdir)/dict.h $(srcdir)/util/rbtree.h $(srcdir)/util-internal.h $(srcdir)/context.h $(srcdir)/extension/default_eventloop.h \
rr-iter.lo rr-iter.o: $(srcdir)/rr-iter.c $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h config.h getdns/getdns.h \ $(srcdir)/extension/poll_eventloop.h $(srcdir)/types-internal.h $(srcdir)/util/uthash.h $(srcdir)/ub_loop.h \
$(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h \
$(srcdir)/gldns/rrdef.h $(srcdir)/gldns/str2wire.h $(srcdir)/gldns/rrdef.h $(srcdir)/dict.h $(srcdir)/convert.h
rr-dict.lo rr-dict.o: $(srcdir)/rr-dict.c $(srcdir)/rr-dict.h \
config.h \
getdns/getdns.h \
$(srcdir)/gldns/gbuffer.h $(srcdir)/util-internal.h $(srcdir)/context.h \
getdns/getdns_extra.h \
$(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/extension/default_eventloop.h \
$(srcdir)/extension/poll_eventloop.h $(srcdir)/types-internal.h $(srcdir)/util/uthash.h $(srcdir)/ub_loop.h \
$(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/rr-iter.h $(srcdir)/gldns/pkthdr.h $(srcdir)/dict.h
rr-iter.lo rr-iter.o: $(srcdir)/rr-iter.c $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h \
config.h \
getdns/getdns.h \
$(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h $(srcdir)/gldns/rrdef.h
server.lo server.o: $(srcdir)/server.c config.h getdns/getdns_extra.h getdns/getdns.h \ server.lo server.o: $(srcdir)/server.c \
$(srcdir)/context.h getdns/getdns.h $(srcdir)/types-internal.h $(srcdir)/util/rbtree.h \ config.h \
$(srcdir)/extension/default_eventloop.h config.h getdns/getdns_extra.h $(srcdir)/ub_loop.h \ getdns/getdns_extra.h \
getdns/getdns.h \
$(srcdir)/context.h $(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/extension/default_eventloop.h \
$(srcdir)/extension/poll_eventloop.h $(srcdir)/types-internal.h $(srcdir)/util/uthash.h $(srcdir)/ub_loop.h \
$(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/debug.h $(srcdir)/server.h
stub.lo stub.o: $(srcdir)/stub.c config.h $(srcdir)/debug.h $(srcdir)/stub.h getdns/getdns.h $(srcdir)/types-internal.h \ stub.lo stub.o: $(srcdir)/stub.c \
getdns/getdns_extra.h getdns/getdns.h $(srcdir)/util/rbtree.h $(srcdir)/gldns/gbuffer.h \ config.h \
$(srcdir)/gldns/pkthdr.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/str2wire.h $(srcdir)/gldns/rrdef.h \ $(srcdir)/debug.h $(srcdir)/stub.h \
$(srcdir)/gldns/wire2str.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/context.h \ getdns/getdns.h \
$(srcdir)/extension/default_eventloop.h config.h getdns/getdns_extra.h $(srcdir)/ub_loop.h \ $(srcdir)/types-internal.h \
$(srcdir)/server.h $(srcdir)/util-internal.h $(srcdir)/general.h $(srcdir)/pubkey-pinning.h getdns/getdns_extra.h \
sync.lo sync.o: $(srcdir)/sync.c getdns/getdns.h config.h $(srcdir)/context.h getdns/getdns_extra.h \ $(srcdir)/util/rbtree.h $(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h $(srcdir)/gldns/rrdef.h \
getdns/getdns.h $(srcdir)/types-internal.h $(srcdir)/util/rbtree.h \ $(srcdir)/gldns/str2wire.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/wire2str.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h \
$(srcdir)/extension/default_eventloop.h config.h getdns/getdns_extra.h $(srcdir)/ub_loop.h \ $(srcdir)/context.h $(srcdir)/extension/default_eventloop.h $(srcdir)/extension/poll_eventloop.h \
$(srcdir)/types-internal.h $(srcdir)/util/uthash.h $(srcdir)/ub_loop.h $(srcdir)/server.h $(srcdir)/util-internal.h \
$(srcdir)/general.h $(srcdir)/pubkey-pinning.h
sync.lo sync.o: $(srcdir)/sync.c \
getdns/getdns.h \
config.h \
$(srcdir)/context.h \
getdns/getdns_extra.h \
$(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/extension/default_eventloop.h \
$(srcdir)/extension/poll_eventloop.h $(srcdir)/types-internal.h $(srcdir)/util/uthash.h $(srcdir)/ub_loop.h \
$(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/general.h $(srcdir)/util-internal.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h \ $(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/general.h $(srcdir)/util-internal.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h \
$(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h $(srcdir)/dnssec.h $(srcdir)/gldns/rrdef.h $(srcdir)/stub.h \ $(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h $(srcdir)/dnssec.h $(srcdir)/gldns/rrdef.h $(srcdir)/stub.h \
$(srcdir)/gldns/wire2str.h $(srcdir)/gldns/wire2str.h
ub_loop.lo ub_loop.o: $(srcdir)/ub_loop.c $(srcdir)/ub_loop.h config.h getdns/getdns.h \ ub_loop.lo ub_loop.o: $(srcdir)/ub_loop.c $(srcdir)/ub_loop.h \
getdns/getdns_extra.h getdns/getdns.h $(srcdir)/types-internal.h $(srcdir)/util/rbtree.h \ config.h \
$(srcdir)/debug.h getdns/getdns.h \
util-internal.lo util-internal.o: $(srcdir)/util-internal.c config.h getdns/getdns.h $(srcdir)/dict.h \ getdns/getdns_extra.h \
$(srcdir)/util/rbtree.h $(srcdir)/types-internal.h getdns/getdns_extra.h getdns/getdns.h \ $(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/debug.h
$(srcdir)/list.h $(srcdir)/util-internal.h $(srcdir)/context.h $(srcdir)/extension/default_eventloop.h config.h \ util-internal.lo util-internal.o: $(srcdir)/util-internal.c \
getdns/getdns_extra.h $(srcdir)/ub_loop.h $(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h \ config.h \
$(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h $(srcdir)/gldns/str2wire.h $(srcdir)/gldns/rrdef.h $(srcdir)/dnssec.h \ getdns/getdns.h \
$(srcdir)/gldns/rrdef.h $(srcdir)/dict.h $(srcdir)/util/rbtree.h $(srcdir)/types-internal.h \
version.lo version.o: version.c getdns/getdns_extra.h \
gbuffer.lo gbuffer.o: $(srcdir)/gldns/gbuffer.c config.h $(srcdir)/gldns/gbuffer.h $(srcdir)/list.h $(srcdir)/util-internal.h $(srcdir)/context.h $(srcdir)/extension/default_eventloop.h \
keyraw.lo keyraw.o: $(srcdir)/gldns/keyraw.c config.h $(srcdir)/gldns/keyraw.h $(srcdir)/gldns/rrdef.h $(srcdir)/extension/poll_eventloop.h $(srcdir)/types-internal.h $(srcdir)/util/uthash.h $(srcdir)/ub_loop.h \
parse.lo parse.o: $(srcdir)/gldns/parse.c config.h $(srcdir)/gldns/parse.h $(srcdir)/gldns/parseutil.h \ $(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h \
$(srcdir)/gldns/str2wire.h $(srcdir)/gldns/rrdef.h $(srcdir)/dnssec.h $(srcdir)/gldns/rrdef.h
gbuffer.lo gbuffer.o: $(srcdir)/gldns/gbuffer.c \
config.h \
$(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/gbuffer.h
parseutil.lo parseutil.o: $(srcdir)/gldns/parseutil.c config.h $(srcdir)/gldns/parseutil.h keyraw.lo keyraw.o: $(srcdir)/gldns/keyraw.c \
rrdef.lo rrdef.o: $(srcdir)/gldns/rrdef.c config.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/parseutil.h config.h \
str2wire.lo str2wire.o: $(srcdir)/gldns/str2wire.c config.h $(srcdir)/gldns/str2wire.h $(srcdir)/gldns/rrdef.h \ $(srcdir)/gldns/keyraw.h $(srcdir)/gldns/rrdef.h
$(srcdir)/gldns/wire2str.h $(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/parse.h $(srcdir)/gldns/parseutil.h parse.lo parse.o: $(srcdir)/gldns/parse.c \
wire2str.lo wire2str.o: $(srcdir)/gldns/wire2str.c config.h $(srcdir)/gldns/wire2str.h $(srcdir)/gldns/str2wire.h \ config.h \
$(srcdir)/gldns/rrdef.h $(srcdir)/gldns/pkthdr.h $(srcdir)/gldns/parseutil.h $(srcdir)/gldns/gbuffer.h \ $(srcdir)/gldns/parse.h $(srcdir)/gldns/parseutil.h $(srcdir)/gldns/gbuffer.h
$(srcdir)/gldns/keyraw.h parseutil.lo parseutil.o: $(srcdir)/gldns/parseutil.c \
arc4_lock.lo arc4_lock.o: $(srcdir)/compat/arc4_lock.c config.h config.h \
arc4random.lo arc4random.o: $(srcdir)/compat/arc4random.c config.h $(srcdir)/compat/chacha_private.h $(srcdir)/gldns/parseutil.h
arc4random_uniform.lo arc4random_uniform.o: $(srcdir)/compat/arc4random_uniform.c config.h rrdef.lo rrdef.o: $(srcdir)/gldns/rrdef.c \
explicit_bzero.lo explicit_bzero.o: $(srcdir)/compat/explicit_bzero.c config.h config.h \
getentropy_linux.lo getentropy_linux.o: $(srcdir)/compat/getentropy_linux.c config.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/parseutil.h
getentropy_osx.lo getentropy_osx.o: $(srcdir)/compat/getentropy_osx.c config.h str2wire.lo str2wire.o: $(srcdir)/gldns/str2wire.c \
getentropy_solaris.lo getentropy_solaris.o: $(srcdir)/compat/getentropy_solaris.c config.h config.h \
$(srcdir)/gldns/str2wire.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/wire2str.h $(srcdir)/gldns/gbuffer.h \
$(srcdir)/gldns/parse.h $(srcdir)/gldns/parseutil.h
wire2str.lo wire2str.o: $(srcdir)/gldns/wire2str.c \
config.h \
$(srcdir)/gldns/wire2str.h $(srcdir)/gldns/str2wire.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/pkthdr.h \
$(srcdir)/gldns/parseutil.h $(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/keyraw.h
arc4_lock.lo arc4_lock.o: $(srcdir)/compat/arc4_lock.c \
config.h
arc4random.lo arc4random.o: $(srcdir)/compat/arc4random.c \
config.h \
$(srcdir)/compat/chacha_private.h
arc4random_uniform.lo arc4random_uniform.o: $(srcdir)/compat/arc4random_uniform.c \
config.h
explicit_bzero.lo explicit_bzero.o: $(srcdir)/compat/explicit_bzero.c \
config.h
getentropy_linux.lo getentropy_linux.o: $(srcdir)/compat/getentropy_linux.c \
config.h
getentropy_osx.lo getentropy_osx.o: $(srcdir)/compat/getentropy_osx.c \
config.h
getentropy_solaris.lo getentropy_solaris.o: $(srcdir)/compat/getentropy_solaris.c \
config.h
getentropy_win.lo getentropy_win.o: $(srcdir)/compat/getentropy_win.c getentropy_win.lo getentropy_win.o: $(srcdir)/compat/getentropy_win.c
gettimeofday.lo gettimeofday.o: $(srcdir)/compat/gettimeofday.c config.h gettimeofday.lo gettimeofday.o: $(srcdir)/compat/gettimeofday.c \
inet_ntop.lo inet_ntop.o: $(srcdir)/compat/inet_ntop.c config.h config.h
inet_pton.lo inet_pton.o: $(srcdir)/compat/inet_pton.c config.h inet_ntop.lo inet_ntop.o: $(srcdir)/compat/inet_ntop.c \
sha512.lo sha512.o: $(srcdir)/compat/sha512.c config.h config.h
strlcpy.lo strlcpy.o: $(srcdir)/compat/strlcpy.c config.h inet_pton.lo inet_pton.o: $(srcdir)/compat/inet_pton.c \
rbtree.lo rbtree.o: $(srcdir)/util/rbtree.c config.h $(srcdir)/util/log.h $(srcdir)/debug.h config.h \ config.h
$(srcdir)/util/fptr_wlist.h $(srcdir)/util/rbtree.h sha512.lo sha512.o: $(srcdir)/compat/sha512.c \
val_secalgo.lo val_secalgo.o: $(srcdir)/util/val_secalgo.c config.h $(srcdir)/util/val_secalgo.h $(srcdir)/util/log.h \ config.h
$(srcdir)/debug.h config.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/keyraw.h $(srcdir)/gldns/gbuffer.h strlcpy.lo strlcpy.o: $(srcdir)/compat/strlcpy.c \
config.h
rbtree.lo rbtree.o: $(srcdir)/util/rbtree.c \
config.h \
$(srcdir)/util/log.h $(srcdir)/debug.h $(srcdir)/util/fptr_wlist.h $(srcdir)/util/rbtree.h
val_secalgo.lo val_secalgo.o: $(srcdir)/util/val_secalgo.c \
config.h \
$(srcdir)/util/val_secalgo.h $(srcdir)/util/log.h $(srcdir)/debug.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/keyraw.h \
$(srcdir)/gldns/gbuffer.h
jsmn.lo jsmn.o: $(srcdir)/jsmn/jsmn.c $(srcdir)/jsmn/jsmn.h jsmn.lo jsmn.o: $(srcdir)/jsmn/jsmn.c $(srcdir)/jsmn/jsmn.h
default_eventloop.lo default_eventloop.o: $(srcdir)/extension/default_eventloop.c config.h \ libev.lo libev.o: $(srcdir)/extension/libev.c \
$(srcdir)/extension/default_eventloop.h getdns/getdns.h getdns/getdns_extra.h \ config.h \
$(srcdir)/debug.h config.h $(srcdir)/types-internal.h getdns/getdns.h getdns/getdns_extra.h \ $(srcdir)/types-internal.h \
$(srcdir)/util/rbtree.h getdns/getdns.h \
libev.lo libev.o: $(srcdir)/extension/libev.c config.h $(srcdir)/types-internal.h getdns/getdns.h \ getdns/getdns_extra.h \
getdns/getdns_extra.h getdns/getdns.h $(srcdir)/util/rbtree.h \ $(srcdir)/util/rbtree.h $(srcdir)/getdns/getdns_ext_libev.h
$(srcdir)/getdns/getdns_ext_libev.h getdns/getdns_extra.h libevent.lo libevent.o: $(srcdir)/extension/libevent.c \
libevent.lo libevent.o: $(srcdir)/extension/libevent.c config.h $(srcdir)/types-internal.h \ config.h \
getdns/getdns.h getdns/getdns_extra.h getdns/getdns.h $(srcdir)/util/rbtree.h \ $(srcdir)/types-internal.h \
$(srcdir)/getdns/getdns_ext_libevent.h getdns/getdns_extra.h getdns/getdns.h \
libuv.lo libuv.o: $(srcdir)/extension/libuv.c config.h $(srcdir)/debug.h config.h $(srcdir)/types-internal.h \ getdns/getdns_extra.h \
getdns/getdns.h getdns/getdns_extra.h getdns/getdns.h $(srcdir)/util/rbtree.h \ $(srcdir)/util/rbtree.h $(srcdir)/getdns/getdns_ext_libevent.h
$(srcdir)/getdns/getdns_ext_libuv.h getdns/getdns_extra.h libuv.lo libuv.o: $(srcdir)/extension/libuv.c \
config.h \
$(srcdir)/debug.h $(srcdir)/types-internal.h \
getdns/getdns.h \
getdns/getdns_extra.h \
$(srcdir)/util/rbtree.h $(srcdir)/getdns/getdns_ext_libuv.h
poll_eventloop.lo poll_eventloop.o: $(srcdir)/extension/poll_eventloop.c \
config.h \
$(srcdir)/extension/poll_eventloop.h \
getdns/getdns.h \
getdns/getdns_extra.h \
$(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/util/uthash.h $(srcdir)/debug.h
select_eventloop.lo select_eventloop.o: $(srcdir)/extension/select_eventloop.c \
config.h \
$(srcdir)/extension/select_eventloop.h \
getdns/getdns.h \
getdns/getdns_extra.h \
$(srcdir)/debug.h $(srcdir)/types-internal.h $(srcdir)/util/rbtree.h

View File

@ -1388,8 +1388,8 @@ getdns_context_create_with_extended_memory_functions(
result->tls_ctx = NULL; result->tls_ctx = NULL;
result->extension = &result->default_eventloop.loop; result->extension = &result->default_eventloop.loop;
_getdns_default_eventloop_init(&result->default_eventloop); _getdns_default_eventloop_init(&result->mf, &result->default_eventloop);
_getdns_default_eventloop_init(&result->sync_eventloop); _getdns_default_eventloop_init(&result->mf, &result->sync_eventloop);
/* request extension defaults /* request extension defaults
*/ */
@ -3403,7 +3403,7 @@ getdns_context_detach_eventloop(struct getdns_context* context)
cancel_outstanding_requests(context, 1); cancel_outstanding_requests(context, 1);
context->extension->vmt->cleanup(context->extension); context->extension->vmt->cleanup(context->extension);
context->extension = &context->default_eventloop.loop; context->extension = &context->default_eventloop.loop;
_getdns_default_eventloop_init(&context->default_eventloop); _getdns_default_eventloop_init(&context->mf, &context->default_eventloop);
#ifdef HAVE_UNBOUND_EVENT_API #ifdef HAVE_UNBOUND_EVENT_API
if (_getdns_ub_loop_enabled(&context->ub_loop)) if (_getdns_ub_loop_enabled(&context->ub_loop))
context->ub_loop.extension = context->extension; context->ub_loop.extension = context->extension;

View File

@ -1,6 +1,6 @@
/* /*
* \file default_eventloop.h * \file default_eventloop.h
* @brief Build in default eventloop extension that uses select. * @brief Build in default eventloop extension that uses either poll or select.
* *
*/ */
/* /*
@ -32,28 +32,13 @@
#ifndef DEFAULT_EVENTLOOP_H_ #ifndef DEFAULT_EVENTLOOP_H_
#define DEFAULT_EVENTLOOP_H_ #define DEFAULT_EVENTLOOP_H_
#include "config.h" #include "config.h"
#include "getdns/getdns.h" #ifdef USE_POLL_DEFAULT_EVENTLOOP
#include "getdns/getdns_extra.h" #include "extension/poll_eventloop.h"
#define _getdns_default_eventloop _getdns_poll_eventloop
/* No more than select's capability queries can be outstanding, #define _getdns_default_eventloop_init _getdns_poll_eventloop_init
* The number of outstanding timeouts should be less or equal then #else
* the number of outstanding queries, so MAX_TIMEOUTS equal to #include "extension/select_eventloop.h"
* FD_SETSIZE should be safe. #define _getdns_default_eventloop _getdns_select_eventloop
*/ #define _getdns_default_eventloop_init _getdns_select_eventloop_init
#define MAX_TIMEOUTS FD_SETSIZE #endif
/* Eventloop based on select */
typedef struct _getdns_default_eventloop {
getdns_eventloop loop;
getdns_eventloop_event *fd_events[FD_SETSIZE];
uint64_t fd_timeout_times[FD_SETSIZE];
getdns_eventloop_event *timeout_events[MAX_TIMEOUTS];
uint64_t timeout_times[MAX_TIMEOUTS];
} _getdns_default_eventloop;
void
_getdns_default_eventloop_init(_getdns_default_eventloop *loop);
#endif #endif

View File

@ -0,0 +1,419 @@
/*
* Copyright (c) 2013, NLNet Labs, Verisign, 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 names of the copyright holders 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 "config.h"
#ifdef HAVE_SYS_POLL_H
#include <sys/poll.h>
#else
#include <poll.h>
#endif
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
#include "extension/poll_eventloop.h"
#include "debug.h"
static _getdns_eventloop_info *
find_event(_getdns_eventloop_info** events, int id)
{
_getdns_eventloop_info* ev;
HASH_FIND_INT(*events, &id, ev);
return ev;
}
static _getdns_eventloop_info *
add_event(struct mem_funcs *mf, _getdns_eventloop_info** events,
int id, getdns_eventloop_event *event, uint64_t timeout_time)
{
DEBUG_SCHED("poll_eventloop: add_event with id %d\n", id);
_getdns_eventloop_info* myevent = GETDNS_MALLOC(*mf, _getdns_eventloop_info);
/* not necessary -- (void) memset(myevent, 0, sizeof(_getdns_eventloop_info)); */
myevent->id = id;
myevent->event = event;
myevent->timeout_time = timeout_time;
HASH_ADD_INT(*events, id, myevent);
return myevent;
}
static void
delete_event(struct mem_funcs *mf,
_getdns_eventloop_info** events, _getdns_eventloop_info* ev)
{
DEBUG_SCHED("poll_eventloop: delete_event with id %d\n", ev->id);
HASH_DEL(*events, ev);
GETDNS_FREE(*mf, ev);
}
static uint64_t get_now_plus(uint64_t amount)
{
struct timeval tv;
uint64_t now;
if (gettimeofday(&tv, NULL)) {
perror("gettimeofday() failed");
exit(EXIT_FAILURE);
}
now = tv.tv_sec * 1000000 + tv.tv_usec;
return (now + amount * 1000) >= now
? now + amount * 1000 : TIMEOUT_FOREVER;
}
static getdns_return_t
poll_eventloop_schedule(getdns_eventloop *loop,
int fd, uint64_t timeout, getdns_eventloop_event *event)
{
_getdns_poll_eventloop *poll_loop = (_getdns_poll_eventloop *)loop;
struct mem_funcs *mf = &poll_loop->mf;
size_t i;
DEBUG_SCHED( "%s(loop: %p, fd: %d, timeout: %"PRIu64", event: %p, max_fds: %d)\n"
, __FUNC__, (void *)loop, fd, timeout, (void *)event, poll_loop->max_fds);
if (!loop || !event)
return GETDNS_RETURN_INVALID_PARAMETER;
#ifdef HAVE_GETRLIMIT
if (fd >= (int)poll_loop->max_fds) {
DEBUG_SCHED( "ERROR: fd %d >= max_fds: %d!\n"
, fd, poll_loop->max_fds);
return GETDNS_RETURN_GENERIC_ERROR;
}
#endif
if (fd >= 0 && !(event->read_cb || event->write_cb)) {
DEBUG_SCHED("WARNING: fd event without "
"read or write cb!\n");
fd = -1;
}
if (fd >= 0) {
_getdns_eventloop_info* fd_event = find_event(&poll_loop->fd_events, fd);
#if defined(SCHED_DEBUG) && SCHED_DEBUG
if (fd_event) {
if (fd_event->event == event) {
DEBUG_SCHED("WARNING: Event %p not cleared "
"before being rescheduled!\n"
, (void *)fd_event->event);
} else {
DEBUG_SCHED("ERROR: A different event is "
"already present at fd slot: %p!\n"
, (void *)fd_event->event);
}
}
#endif
/* cleanup the old event if it exists */
if (fd_event) {
delete_event(mf, &poll_loop->fd_events, fd_event);
}
event->ev = add_event(mf, &poll_loop->fd_events, fd, event, get_now_plus(timeout));
DEBUG_SCHED( "scheduled read/write at fd %d\n", fd);
return GETDNS_RETURN_GOOD;
}
if (!event->timeout_cb) {
DEBUG_SCHED("ERROR: fd < 0 without timeout_cb!\n");
return GETDNS_RETURN_GENERIC_ERROR;
}
if (event->read_cb) {
DEBUG_SCHED("ERROR: timeout event with read_cb! Clearing.\n");
event->read_cb = NULL;
}
if (event->write_cb) {
DEBUG_SCHED("ERROR: timeout event with write_cb! Clearing.\n");
event->write_cb = NULL;
}
for (i = poll_loop->timeout_id + 1; i != poll_loop->timeout_id; i++) {
if (find_event(&poll_loop->timeout_events, i) == NULL) {
event->ev = add_event(mf, &poll_loop->timeout_events, i, event, get_now_plus(timeout));
DEBUG_SCHED( "scheduled timeout at slot %d\n", (int)i);
return GETDNS_RETURN_GOOD;
}
}
DEBUG_SCHED("ERROR: Out of timeout slots!\n");
return GETDNS_RETURN_GENERIC_ERROR;
}
static getdns_return_t
poll_eventloop_clear(getdns_eventloop *loop, getdns_eventloop_event *event)
{
_getdns_poll_eventloop *poll_loop = (_getdns_poll_eventloop *)loop;
struct mem_funcs *mf = &poll_loop->mf;
if (!loop || !event)
return GETDNS_RETURN_INVALID_PARAMETER;
DEBUG_SCHED( "%s(loop: %p, event: %p)\n", __FUNC__, (void *)loop, (void *)event);
assert(event->ev);
delete_event(mf,
( event->timeout_cb && !event->read_cb && !event->write_cb
? &poll_loop->timeout_events : &poll_loop->fd_events
), event->ev);
event->ev = NULL;
return GETDNS_RETURN_GOOD;
}
static void
poll_eventloop_cleanup(getdns_eventloop *loop)
{
_getdns_poll_eventloop *poll_loop = (_getdns_poll_eventloop *)loop;
struct mem_funcs *mf = &poll_loop->mf;
if (poll_loop->pfds) {
GETDNS_FREE(*mf, poll_loop->pfds);
poll_loop->pfds = NULL;
poll_loop->pfds_capacity = 0;
}
HASH_CLEAR(hh, poll_loop->fd_events);
HASH_CLEAR(hh, poll_loop->timeout_events);
}
static void
poll_read_cb(int fd, getdns_eventloop_event *event)
{
#if !defined(SCHED_DEBUG) || !SCHED_DEBUG
(void)fd;
#endif
DEBUG_SCHED( "%s(fd: %d, event: %p)\n", __FUNC__, fd, (void *)event);
event->read_cb(event->userarg);
}
static void
poll_write_cb(int fd, getdns_eventloop_event *event)
{
#if !defined(SCHED_DEBUG) || !SCHED_DEBUG
(void)fd;
#endif
DEBUG_SCHED( "%s(fd: %d, event: %p)\n", __FUNC__, fd, (void *)event);
event->write_cb(event->userarg);
}
static void
poll_timeout_cb(int fd, getdns_eventloop_event *event)
{
#if !defined(SCHED_DEBUG) || !SCHED_DEBUG
(void)fd;
#endif
DEBUG_SCHED( "%s(fd: %d, event: %p)\n", __FUNC__, fd, (void *)event);
event->timeout_cb(event->userarg);
}
static unsigned long up_pow2(unsigned long v)
{
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
return v + 1;
}
static void
poll_eventloop_run_once(getdns_eventloop *loop, int blocking)
{
_getdns_poll_eventloop *poll_loop = (_getdns_poll_eventloop *)loop;
struct mem_funcs *mf = &poll_loop->mf;
_getdns_eventloop_info *s, *tmp;
uint64_t now, timeout = TIMEOUT_FOREVER;
size_t i=0;
int poll_timeout = 0;
unsigned int num_pfds = 0;
_getdns_eventloop_info* timeout_timeout_cbs = NULL;
_getdns_eventloop_info* fd_timeout_cbs = NULL;
if (!loop)
return;
now = get_now_plus(0);
HASH_ITER(hh, poll_loop->timeout_events, s, tmp) {
if (now > s->timeout_time)
(void) add_event(mf, &timeout_timeout_cbs, s->id, s->event, s->timeout_time);
else if (s->timeout_time < timeout)
timeout = s->timeout_time;
}
/* this is in case the timeout callback deletes the event
and thus messes with the iteration */
HASH_ITER(hh, timeout_timeout_cbs, s, tmp) {
getdns_eventloop_event* event = s->event;
delete_event(mf, &timeout_timeout_cbs, s);
poll_timeout_cb(-1, event);
}
/* first we count the number of fds that will be active */
HASH_ITER(hh, poll_loop->fd_events, s, tmp) {
if (s->event->read_cb ||
s->event->write_cb)
num_pfds++;
if (s->timeout_time < timeout)
timeout = s->timeout_time;
}
if ((timeout == TIMEOUT_FOREVER) && (num_pfds == 0))
return;
if (num_pfds >= poll_loop->pfds_capacity) {
poll_loop->pfds_capacity = up_pow2(num_pfds + 1);
if (!poll_loop->pfds) {
poll_loop->pfds = GETDNS_XMALLOC(poll_loop->mf, struct pollfd, poll_loop->pfds_capacity);
} else
poll_loop->pfds = GETDNS_XREALLOC(poll_loop->mf, poll_loop->pfds, struct pollfd, poll_loop->pfds_capacity);
if (poll_loop->pfds == 0) {
poll_loop->pfds_capacity = 0;
return;
}
}
i = 0;
HASH_ITER(hh, poll_loop->fd_events, s, tmp) {
if (!s->event->read_cb && !s->event->write_cb)
continue;
poll_loop->pfds[i].fd = s->id;
poll_loop->pfds[i].events = 0;
poll_loop->pfds[i].revents = 0; /* <-- probably not needed */
if (s->event->read_cb)
poll_loop->pfds[i].events |= POLLIN;
if (s->event->write_cb)
poll_loop->pfds[i].events |= POLLOUT;
i++;
}
assert(i == num_pfds);
if (timeout == TIMEOUT_FOREVER) {
poll_timeout = -1;
}
else if (! blocking || now > timeout) {
poll_timeout = 0;
} else {
poll_timeout = (timeout - now) / 1000; /* turn microseconds into milliseconds */
}
#ifdef USE_WINSOCK
if (WSAPoll(poll_loop->pfds, num_pfds, poll_timeout) < 0) {
#else
if (poll(poll_loop->pfds, num_pfds, poll_timeout) < 0) {
#endif
perror("poll() failed");
exit(EXIT_FAILURE);
}
now = get_now_plus(0);
for (i = 0; i < num_pfds; i++) {
int fd = poll_loop->pfds[i].fd;
_getdns_eventloop_info* fd_event = find_event(&poll_loop->fd_events, fd);
if (fd_event && fd_event->event) {
getdns_eventloop_event* event = fd_event->event;
if (event->write_cb &&
(poll_loop->pfds[i].revents & POLLOUT))
poll_write_cb(fd, event);
else if (event->read_cb &&
(poll_loop->pfds[i].revents & POLLIN))
poll_read_cb(fd, event);
}
}
HASH_ITER(hh, poll_loop->fd_events, s, tmp) {
if (s->event &&
s->event->timeout_cb &&
now > s->timeout_time)
(void) add_event(mf, &fd_timeout_cbs, s->id, s->event, s->timeout_time);
}
/* this is in case the timeout callback deletes the event
and thus messes with the iteration */
HASH_ITER(hh, fd_timeout_cbs, s, tmp) {
int fd = s->id;
getdns_eventloop_event* event = s->event;
delete_event(mf, &fd_timeout_cbs, s);
poll_timeout_cb(fd, event);
}
HASH_ITER(hh, poll_loop->timeout_events, s, tmp) {
if (s->event &&
s->event->timeout_cb &&
now > s->timeout_time)
(void) add_event(mf, &timeout_timeout_cbs, s->id, s->event, s->timeout_time);
}
/* this is in case the timeout callback deletes the event
and thus messes with the iteration */
HASH_ITER(hh, timeout_timeout_cbs, s, tmp) {
getdns_eventloop_event* event = s->event;
delete_event(mf, &timeout_timeout_cbs, s);
poll_timeout_cb(-1, event);
}
}
static void
poll_eventloop_run(getdns_eventloop *loop)
{
_getdns_poll_eventloop *poll_loop = (_getdns_poll_eventloop *)loop;
if (!loop)
return;
/* keep going until all the events are cleared */
while (poll_loop->fd_events || poll_loop->timeout_events) {
poll_eventloop_run_once(loop, 1);
}
}
void
_getdns_poll_eventloop_init(struct mem_funcs *mf, _getdns_poll_eventloop *loop)
{
#ifdef HAVE_GETRLIMIT
struct rlimit rl;
#endif
static getdns_eventloop_vmt poll_eventloop_vmt = {
poll_eventloop_cleanup,
poll_eventloop_schedule,
poll_eventloop_clear,
poll_eventloop_run,
poll_eventloop_run_once
};
loop->loop.vmt = &poll_eventloop_vmt;
loop->mf = *mf;
#ifdef HAVE_GETRLIMIT
if (getrlimit(RLIMIT_NOFILE, &rl) == 0) {
loop->max_fds = rl.rlim_cur;
} else {
DEBUG_SCHED("ERROR: could not obtain RLIMIT_NOFILE from getrlimit()\n");
#endif
loop->max_fds = 0;
#if HAVE_GETRLIMIT
}
#endif
loop->timeout_id = 0;
loop->pfds = NULL;
loop->pfds_capacity = 0;
loop->fd_events = NULL;
loop->timeout_events = NULL;
}

View File

@ -0,0 +1,67 @@
/*
* \file poll_eventloop.h
* @brief Build in default eventloop extension that uses select.
*
*/
/*
* Copyright (c) 2013, NLNet Labs, Verisign, 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 names of the copyright holders 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 POLL_EVENTLOOP_H_
#define POLL_EVENTLOOP_H_
#include "config.h"
#include "getdns/getdns.h"
#include "getdns/getdns_extra.h"
#include "types-internal.h"
#define uthash_malloc(sz) ((void *)GETDNS_XMALLOC(*mf, unsigned char, sz))
#define uthash_free(ptr,sz) GETDNS_FREE(*mf, ptr)
#include "util/uthash.h"
/* Eventloop based on poll */
typedef struct _getdns_eventloop_info {
int id;
getdns_eventloop_event *event;
uint64_t timeout_time;
UT_hash_handle hh;
} _getdns_eventloop_info;
typedef struct _getdns_poll_eventloop {
getdns_eventloop loop;
struct mem_funcs mf;
unsigned int max_fds;
unsigned int timeout_id;
struct pollfd *pfds;
unsigned long pfds_capacity;
_getdns_eventloop_info *fd_events;
_getdns_eventloop_info *timeout_events;
} _getdns_poll_eventloop;
void
_getdns_poll_eventloop_init(struct mem_funcs *mf, _getdns_poll_eventloop *loop);
#endif

View File

@ -27,7 +27,7 @@
#include "config.h" #include "config.h"
#include "extension/default_eventloop.h" #include "extension/select_eventloop.h"
#include "debug.h" #include "debug.h"
#include "types-internal.h" #include "types-internal.h"
@ -47,10 +47,10 @@ static uint64_t get_now_plus(uint64_t amount)
} }
static getdns_return_t static getdns_return_t
default_eventloop_schedule(getdns_eventloop *loop, select_eventloop_schedule(getdns_eventloop *loop,
int fd, uint64_t timeout, getdns_eventloop_event *event) int fd, uint64_t timeout, getdns_eventloop_event *event)
{ {
_getdns_default_eventloop *default_loop = (_getdns_default_eventloop *)loop; _getdns_select_eventloop *select_loop = (_getdns_select_eventloop *)loop;
size_t i; size_t i;
DEBUG_SCHED( "%s(loop: %p, fd: %d, timeout: %"PRIu64", event: %p, FD_SETSIZE: %d)\n" DEBUG_SCHED( "%s(loop: %p, fd: %d, timeout: %"PRIu64", event: %p, FD_SETSIZE: %d)\n"
@ -71,20 +71,20 @@ default_eventloop_schedule(getdns_eventloop *loop,
} }
if (fd >= 0) { if (fd >= 0) {
#if defined(SCHED_DEBUG) && SCHED_DEBUG #if defined(SCHED_DEBUG) && SCHED_DEBUG
if (default_loop->fd_events[fd]) { if (select_loop->fd_events[fd]) {
if (default_loop->fd_events[fd] == event) { if (select_loop->fd_events[fd] == event) {
DEBUG_SCHED("WARNING: Event %p not cleared " DEBUG_SCHED("WARNING: Event %p not cleared "
"before being rescheduled!\n" "before being rescheduled!\n"
, (void *)default_loop->fd_events[fd]); , (void *)select_loop->fd_events[fd]);
} else { } else {
DEBUG_SCHED("ERROR: A different event is " DEBUG_SCHED("ERROR: A different event is "
"already present at fd slot: %p!\n" "already present at fd slot: %p!\n"
, (void *)default_loop->fd_events[fd]); , (void *)select_loop->fd_events[fd]);
} }
} }
#endif #endif
default_loop->fd_events[fd] = event; select_loop->fd_events[fd] = event;
default_loop->fd_timeout_times[fd] = get_now_plus(timeout); select_loop->fd_timeout_times[fd] = get_now_plus(timeout);
event->ev = (void *)(intptr_t)(fd + 1); event->ev = (void *)(intptr_t)(fd + 1);
DEBUG_SCHED( "scheduled read/write at %d\n", fd); DEBUG_SCHED( "scheduled read/write at %d\n", fd);
return GETDNS_RETURN_GOOD; return GETDNS_RETURN_GOOD;
@ -102,9 +102,9 @@ default_eventloop_schedule(getdns_eventloop *loop,
event->write_cb = NULL; event->write_cb = NULL;
} }
for (i = 0; i < MAX_TIMEOUTS; i++) { for (i = 0; i < MAX_TIMEOUTS; i++) {
if (default_loop->timeout_events[i] == NULL) { if (select_loop->timeout_events[i] == NULL) {
default_loop->timeout_events[i] = event; select_loop->timeout_events[i] = event;
default_loop->timeout_times[i] = get_now_plus(timeout); select_loop->timeout_times[i] = get_now_plus(timeout);
event->ev = (void *)(intptr_t)(i + 1); event->ev = (void *)(intptr_t)(i + 1);
DEBUG_SCHED( "scheduled timeout at %d\n", (int)i); DEBUG_SCHED( "scheduled timeout at %d\n", (int)i);
return GETDNS_RETURN_GOOD; return GETDNS_RETURN_GOOD;
@ -115,9 +115,9 @@ default_eventloop_schedule(getdns_eventloop *loop,
} }
static getdns_return_t static getdns_return_t
default_eventloop_clear(getdns_eventloop *loop, getdns_eventloop_event *event) select_eventloop_clear(getdns_eventloop *loop, getdns_eventloop_event *event)
{ {
_getdns_default_eventloop *default_loop = (_getdns_default_eventloop *)loop; _getdns_select_eventloop *select_loop = (_getdns_select_eventloop *)loop;
ssize_t i; ssize_t i;
if (!loop || !event) if (!loop || !event)
@ -131,33 +131,33 @@ default_eventloop_clear(getdns_eventloop *loop, getdns_eventloop_event *event)
} }
if (event->timeout_cb && !event->read_cb && !event->write_cb) { if (event->timeout_cb && !event->read_cb && !event->write_cb) {
#if defined(SCHED_DEBUG) && SCHED_DEBUG #if defined(SCHED_DEBUG) && SCHED_DEBUG
if (default_loop->timeout_events[i] != event) if (select_loop->timeout_events[i] != event)
DEBUG_SCHED( "ERROR: Different/wrong event present at " DEBUG_SCHED( "ERROR: Different/wrong event present at "
"timeout slot: %p!\n" "timeout slot: %p!\n"
, (void *)default_loop->timeout_events[i]); , (void *)select_loop->timeout_events[i]);
#endif #endif
default_loop->timeout_events[i] = NULL; select_loop->timeout_events[i] = NULL;
} else { } else {
#if defined(SCHED_DEBUG) && SCHED_DEBUG #if defined(SCHED_DEBUG) && SCHED_DEBUG
if (default_loop->fd_events[i] != event) if (select_loop->fd_events[i] != event)
DEBUG_SCHED( "ERROR: Different/wrong event present at " DEBUG_SCHED( "ERROR: Different/wrong event present at "
"fd slot: %p!\n" "fd slot: %p!\n"
, (void *)default_loop->fd_events[i]); , (void *)select_loop->fd_events[i]);
#endif #endif
default_loop->fd_events[i] = NULL; select_loop->fd_events[i] = NULL;
} }
event->ev = NULL; event->ev = NULL;
return GETDNS_RETURN_GOOD; return GETDNS_RETURN_GOOD;
} }
static void static void
default_eventloop_cleanup(getdns_eventloop *loop) select_eventloop_cleanup(getdns_eventloop *loop)
{ {
(void)loop; (void)loop;
} }
static void static void
default_read_cb(int fd, getdns_eventloop_event *event) select_read_cb(int fd, getdns_eventloop_event *event)
{ {
#if !defined(SCHED_DEBUG) || !SCHED_DEBUG #if !defined(SCHED_DEBUG) || !SCHED_DEBUG
(void)fd; (void)fd;
@ -167,7 +167,7 @@ default_read_cb(int fd, getdns_eventloop_event *event)
} }
static void static void
default_write_cb(int fd, getdns_eventloop_event *event) select_write_cb(int fd, getdns_eventloop_event *event)
{ {
#if !defined(SCHED_DEBUG) || !SCHED_DEBUG #if !defined(SCHED_DEBUG) || !SCHED_DEBUG
(void)fd; (void)fd;
@ -177,7 +177,7 @@ default_write_cb(int fd, getdns_eventloop_event *event)
} }
static void static void
default_timeout_cb(int fd, getdns_eventloop_event *event) select_timeout_cb(int fd, getdns_eventloop_event *event)
{ {
#if !defined(SCHED_DEBUG) || !SCHED_DEBUG #if !defined(SCHED_DEBUG) || !SCHED_DEBUG
(void)fd; (void)fd;
@ -187,9 +187,9 @@ default_timeout_cb(int fd, getdns_eventloop_event *event)
} }
static void static void
default_eventloop_run_once(getdns_eventloop *loop, int blocking) select_eventloop_run_once(getdns_eventloop *loop, int blocking)
{ {
_getdns_default_eventloop *default_loop = (_getdns_default_eventloop *)loop; _getdns_select_eventloop *select_loop = (_getdns_select_eventloop *)loop;
fd_set readfds, writefds; fd_set readfds, writefds;
int fd, max_fd = -1; int fd, max_fd = -1;
@ -205,24 +205,24 @@ default_eventloop_run_once(getdns_eventloop *loop, int blocking)
now = get_now_plus(0); now = get_now_plus(0);
for (i = 0; i < MAX_TIMEOUTS; i++) { for (i = 0; i < MAX_TIMEOUTS; i++) {
if (!default_loop->timeout_events[i]) if (!select_loop->timeout_events[i])
continue; continue;
if (now > default_loop->timeout_times[i]) if (now > select_loop->timeout_times[i])
default_timeout_cb(-1, default_loop->timeout_events[i]); select_timeout_cb(-1, select_loop->timeout_events[i]);
else if (default_loop->timeout_times[i] < timeout) else if (select_loop->timeout_times[i] < timeout)
timeout = default_loop->timeout_times[i]; timeout = select_loop->timeout_times[i];
} }
for (fd = 0; fd < (int)FD_SETSIZE; fd++) { for (fd = 0; fd < (int)FD_SETSIZE; fd++) {
if (!default_loop->fd_events[fd]) if (!select_loop->fd_events[fd])
continue; continue;
if (default_loop->fd_events[fd]->read_cb) if (select_loop->fd_events[fd]->read_cb)
FD_SET(fd, &readfds); FD_SET(fd, &readfds);
if (default_loop->fd_events[fd]->write_cb) if (select_loop->fd_events[fd]->write_cb)
FD_SET(fd, &writefds); FD_SET(fd, &writefds);
if (fd > max_fd) if (fd > max_fd)
max_fd = fd; max_fd = fd;
if (default_loop->fd_timeout_times[fd] < timeout) if (select_loop->fd_timeout_times[fd] < timeout)
timeout = default_loop->fd_timeout_times[fd]; timeout = select_loop->fd_timeout_times[fd];
} }
if (max_fd == -1 && timeout == TIMEOUT_FOREVER) if (max_fd == -1 && timeout == TIMEOUT_FOREVER)
return; return;
@ -241,33 +241,33 @@ default_eventloop_run_once(getdns_eventloop *loop, int blocking)
} }
now = get_now_plus(0); now = get_now_plus(0);
for (fd = 0; fd < (int)FD_SETSIZE; fd++) { for (fd = 0; fd < (int)FD_SETSIZE; fd++) {
if (default_loop->fd_events[fd] && if (select_loop->fd_events[fd] &&
default_loop->fd_events[fd]->read_cb && select_loop->fd_events[fd]->read_cb &&
FD_ISSET(fd, &readfds)) FD_ISSET(fd, &readfds))
default_read_cb(fd, default_loop->fd_events[fd]); select_read_cb(fd, select_loop->fd_events[fd]);
if (default_loop->fd_events[fd] && if (select_loop->fd_events[fd] &&
default_loop->fd_events[fd]->write_cb && select_loop->fd_events[fd]->write_cb &&
FD_ISSET(fd, &writefds)) FD_ISSET(fd, &writefds))
default_write_cb(fd, default_loop->fd_events[fd]); select_write_cb(fd, select_loop->fd_events[fd]);
if (default_loop->fd_events[fd] && if (select_loop->fd_events[fd] &&
default_loop->fd_events[fd]->timeout_cb && select_loop->fd_events[fd]->timeout_cb &&
now > default_loop->fd_timeout_times[fd]) now > select_loop->fd_timeout_times[fd])
default_timeout_cb(fd, default_loop->fd_events[fd]); select_timeout_cb(fd, select_loop->fd_events[fd]);
i = fd; i = fd;
if (default_loop->timeout_events[i] && if (select_loop->timeout_events[i] &&
default_loop->timeout_events[i]->timeout_cb && select_loop->timeout_events[i]->timeout_cb &&
now > default_loop->timeout_times[i]) now > select_loop->timeout_times[i])
default_timeout_cb(-1, default_loop->timeout_events[i]); select_timeout_cb(-1, select_loop->timeout_events[i]);
} }
} }
static void static void
default_eventloop_run(getdns_eventloop *loop) select_eventloop_run(getdns_eventloop *loop)
{ {
_getdns_default_eventloop *default_loop = (_getdns_default_eventloop *)loop; _getdns_select_eventloop *select_loop = (_getdns_select_eventloop *)loop;
size_t i; size_t i;
if (!loop) if (!loop)
@ -275,8 +275,8 @@ default_eventloop_run(getdns_eventloop *loop)
i = 0; i = 0;
while (i < MAX_TIMEOUTS) { while (i < MAX_TIMEOUTS) {
if (default_loop->fd_events[i] || default_loop->timeout_events[i]) { if (select_loop->fd_events[i] || select_loop->timeout_events[i]) {
default_eventloop_run_once(loop, 1); select_eventloop_run_once(loop, 1);
i = 0; i = 0;
} else { } else {
i++; i++;
@ -285,16 +285,16 @@ default_eventloop_run(getdns_eventloop *loop)
} }
void void
_getdns_default_eventloop_init(_getdns_default_eventloop *loop) _getdns_select_eventloop_init(struct mem_funcs *mf, _getdns_select_eventloop *loop)
{ {
static getdns_eventloop_vmt default_eventloop_vmt = { static getdns_eventloop_vmt select_eventloop_vmt = {
default_eventloop_cleanup, select_eventloop_cleanup,
default_eventloop_schedule, select_eventloop_schedule,
default_eventloop_clear, select_eventloop_clear,
default_eventloop_run, select_eventloop_run,
default_eventloop_run_once select_eventloop_run_once
}; };
(void) mf;
(void) memset(loop, 0, sizeof(_getdns_default_eventloop)); (void) memset(loop, 0, sizeof(_getdns_select_eventloop));
loop->loop.vmt = &default_eventloop_vmt; loop->loop.vmt = &select_eventloop_vmt;
} }

View File

@ -0,0 +1,58 @@
/*
* \file select_eventloop.h
* @brief Build in default eventloop extension that uses select.
*
*/
/*
* Copyright (c) 2013, NLNet Labs, Verisign, 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 names of the copyright holders 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 SELECT_EVENTLOOP_H_
#define SELECT_EVENTLOOP_H_
#include "config.h"
#include "getdns/getdns.h"
#include "getdns/getdns_extra.h"
/* No more than select's capability queries can be outstanding,
* The number of outstanding timeouts should be less or equal then
* the number of outstanding queries, so MAX_TIMEOUTS equal to
* FD_SETSIZE should be safe.
*/
#define MAX_TIMEOUTS FD_SETSIZE
/* Eventloop based on select */
typedef struct _getdns_select_eventloop {
getdns_eventloop loop;
getdns_eventloop_event *fd_events[FD_SETSIZE];
uint64_t fd_timeout_times[FD_SETSIZE];
getdns_eventloop_event *timeout_events[MAX_TIMEOUTS];
uint64_t timeout_times[MAX_TIMEOUTS];
} _getdns_select_eventloop;
void
_getdns_select_eventloop_init(struct mem_funcs *mf, _getdns_select_eventloop *loop);
#endif

@ -1 +1 @@
Subproject commit 49024a6e11739c866bce0e9f3617278b98906ad0 Subproject commit 868c22e35ec223fc26ddefdb9ca83901dc6e2534

View File

@ -216,10 +216,13 @@ depend:
.PHONY: clean test .PHONY: clean test
# Dependencies for the unit tests # Dependencies for the unit tests
check_getdns.lo check_getdns.o: $(srcdir)/check_getdns.c ../getdns/getdns.h $(srcdir)/check_getdns_common.h \ check_getdns.lo check_getdns.o: $(srcdir)/check_getdns.c \
../getdns/getdns_extra.h $(srcdir)/check_getdns_address.h \ ../getdns/getdns.h \
$(srcdir)/check_getdns_address_sync.h $(srcdir)/check_getdns_cancel_callback.h \ $(srcdir)/check_getdns_common.h \
$(srcdir)/check_getdns_context_create.h $(srcdir)/check_getdns_context_destroy.h \ ../getdns/getdns_extra.h \
$(srcdir)/check_getdns_address.h $(srcdir)/check_getdns_address_sync.h \
$(srcdir)/check_getdns_cancel_callback.h $(srcdir)/check_getdns_context_create.h \
$(srcdir)/check_getdns_context_destroy.h \
$(srcdir)/check_getdns_context_set_context_update_callback.h \ $(srcdir)/check_getdns_context_set_context_update_callback.h \
$(srcdir)/check_getdns_context_set_dns_transport.h \ $(srcdir)/check_getdns_context_set_dns_transport.h \
$(srcdir)/check_getdns_context_set_timeout.h \ $(srcdir)/check_getdns_context_set_timeout.h \
@ -239,34 +242,58 @@ check_getdns.lo check_getdns.o: $(srcdir)/check_getdns.c ../getdns/getdns.h $(sr
$(srcdir)/check_getdns_list_get_list.h $(srcdir)/check_getdns_pretty_print_dict.h \ $(srcdir)/check_getdns_list_get_list.h $(srcdir)/check_getdns_pretty_print_dict.h \
$(srcdir)/check_getdns_service.h $(srcdir)/check_getdns_service_sync.h \ $(srcdir)/check_getdns_service.h $(srcdir)/check_getdns_service_sync.h \
$(srcdir)/check_getdns_transport.h $(srcdir)/check_getdns_transport.h
check_getdns_common.lo check_getdns_common.o: $(srcdir)/check_getdns_common.c ../getdns/getdns.h \ check_getdns_common.lo check_getdns_common.o: $(srcdir)/check_getdns_common.c \
../config.h $(srcdir)/check_getdns_common.h ../getdns/getdns_extra.h \ ../getdns/getdns.h \
../config.h \
$(srcdir)/check_getdns_common.h \
../getdns/getdns_extra.h \
$(srcdir)/check_getdns_eventloop.h $(srcdir)/check_getdns_eventloop.h
check_getdns_context_set_timeout.lo check_getdns_context_set_timeout.o: $(srcdir)/check_getdns_context_set_timeout.c \ check_getdns_context_set_timeout.lo check_getdns_context_set_timeout.o: $(srcdir)/check_getdns_context_set_timeout.c \
$(srcdir)/check_getdns_context_set_timeout.h $(srcdir)/check_getdns_common.h \ $(srcdir)/check_getdns_context_set_timeout.h $(srcdir)/check_getdns_common.h \
../getdns/getdns.h ../getdns/getdns_extra.h ../getdns/getdns.h \
../getdns/getdns_extra.h
check_getdns_libev.lo check_getdns_libev.o: $(srcdir)/check_getdns_libev.c $(srcdir)/check_getdns_eventloop.h \ check_getdns_libev.lo check_getdns_libev.o: $(srcdir)/check_getdns_libev.c $(srcdir)/check_getdns_eventloop.h \
../config.h ../getdns/getdns.h $(srcdir)/../getdns/getdns_ext_libev.h \ ../config.h \
../getdns/getdns_extra.h $(srcdir)/check_getdns_common.h ../getdns/getdns.h \
$(srcdir)/../getdns/getdns_ext_libev.h \
../getdns/getdns_extra.h \
$(srcdir)/check_getdns_common.h
check_getdns_libevent.lo check_getdns_libevent.o: $(srcdir)/check_getdns_libevent.c $(srcdir)/check_getdns_eventloop.h \ check_getdns_libevent.lo check_getdns_libevent.o: $(srcdir)/check_getdns_libevent.c $(srcdir)/check_getdns_eventloop.h \
../config.h ../getdns/getdns.h $(srcdir)/../getdns/getdns_ext_libevent.h \ ../config.h \
../getdns/getdns_extra.h $(srcdir)/check_getdns_libevent.h $(srcdir)/check_getdns_common.h ../getdns/getdns.h \
$(srcdir)/../getdns/getdns_ext_libevent.h \
../getdns/getdns_extra.h \
$(srcdir)/check_getdns_libevent.h $(srcdir)/check_getdns_common.h
check_getdns_libuv.lo check_getdns_libuv.o: $(srcdir)/check_getdns_libuv.c $(srcdir)/check_getdns_eventloop.h \ check_getdns_libuv.lo check_getdns_libuv.o: $(srcdir)/check_getdns_libuv.c $(srcdir)/check_getdns_eventloop.h \
../config.h ../getdns/getdns.h $(srcdir)/../getdns/getdns_ext_libuv.h \ ../config.h \
../getdns/getdns_extra.h $(srcdir)/check_getdns_common.h ../getdns/getdns.h \
$(srcdir)/../getdns/getdns_ext_libuv.h \
../getdns/getdns_extra.h \
$(srcdir)/check_getdns_common.h
check_getdns_selectloop.lo check_getdns_selectloop.o: $(srcdir)/check_getdns_selectloop.c \ check_getdns_selectloop.lo check_getdns_selectloop.o: $(srcdir)/check_getdns_selectloop.c \
$(srcdir)/check_getdns_eventloop.h ../config.h ../getdns/getdns.h \ $(srcdir)/check_getdns_eventloop.h \
../config.h \
../getdns/getdns.h \
../getdns/getdns_extra.h ../getdns/getdns_extra.h
check_getdns_transport.lo check_getdns_transport.o: $(srcdir)/check_getdns_transport.c \ check_getdns_transport.lo check_getdns_transport.o: $(srcdir)/check_getdns_transport.c \
$(srcdir)/check_getdns_transport.h $(srcdir)/check_getdns_common.h ../getdns/getdns.h \ $(srcdir)/check_getdns_transport.h $(srcdir)/check_getdns_common.h \
../getdns/getdns.h \
../getdns/getdns_extra.h ../getdns/getdns_extra.h
scratchpad.template.lo scratchpad.template.o: scratchpad.template.c ../getdns/getdns.h \ scratchpad.template.lo scratchpad.template.o: scratchpad.template.c \
../getdns/getdns.h \
../getdns/getdns_extra.h ../getdns/getdns_extra.h
testmessages.lo testmessages.o: $(srcdir)/testmessages.c $(srcdir)/testmessages.h testmessages.lo testmessages.o: $(srcdir)/testmessages.c $(srcdir)/testmessages.h
tests_dict.lo tests_dict.o: $(srcdir)/tests_dict.c $(srcdir)/testmessages.h ../getdns/getdns.h tests_dict.lo tests_dict.o: $(srcdir)/tests_dict.c $(srcdir)/testmessages.h \
tests_list.lo tests_list.o: $(srcdir)/tests_list.c $(srcdir)/testmessages.h ../getdns/getdns.h ../getdns/getdns.h
tests_namespaces.lo tests_namespaces.o: $(srcdir)/tests_namespaces.c $(srcdir)/testmessages.h ../getdns/getdns.h tests_list.lo tests_list.o: $(srcdir)/tests_list.c $(srcdir)/testmessages.h \
tests_stub_async.lo tests_stub_async.o: $(srcdir)/tests_stub_async.c ../config.h $(srcdir)/testmessages.h \ ../getdns/getdns.h
../getdns/getdns.h ../getdns/getdns_extra.h tests_namespaces.lo tests_namespaces.o: $(srcdir)/tests_namespaces.c $(srcdir)/testmessages.h \
tests_stub_sync.lo tests_stub_sync.o: $(srcdir)/tests_stub_sync.c $(srcdir)/testmessages.h ../getdns/getdns.h \ ../getdns/getdns.h
tests_stub_async.lo tests_stub_async.o: $(srcdir)/tests_stub_async.c \
../config.h \
$(srcdir)/testmessages.h \
../getdns/getdns.h \
../getdns/getdns_extra.h
tests_stub_sync.lo tests_stub_sync.o: $(srcdir)/tests_stub_sync.c $(srcdir)/testmessages.h \
../getdns/getdns.h \
../getdns/getdns_extra.h ../getdns/getdns_extra.h

7
src/test/tpkg/clean.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
export SRCDIR=`dirname $0`
( cd $SRCDIR
./tpkg clean
rm -fr build build-stub-only build-event-loops install scan-build-reports .tpkg.var.master
)

View File

@ -113,5 +113,8 @@ depend:
.PHONY: clean test .PHONY: clean test
# Dependencies for getdns_query # Dependencies for getdns_query
getdns_query.lo getdns_query.o: $(srcdir)/getdns_query.c ../config.h $(srcdir)/../debug.h ../config.h \ getdns_query.lo getdns_query.o: $(srcdir)/getdns_query.c \
../getdns/getdns.h ../getdns/getdns_extra.h ../config.h \
$(srcdir)/../debug.h \
../getdns/getdns.h \
../getdns/getdns_extra.h

1074
src/util/uthash.h Normal file

File diff suppressed because it is too large Load Diff