diff --git a/Makefile.am b/Makefile.am index 1a4d64ee..0f995df6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -59,7 +59,7 @@ VERSION_INFO = 1:0:0 dist_bin_SCRIPTS = event_rpcgen.py pkgconfigdir=$(libdir)/pkgconfig -pkgconfig_DATA=libevent.pc +LIBEVENT_PKGCONFIG=libevent.pc # These sources are conditionally added by configure.in or conditionally # included from other files. @@ -76,14 +76,21 @@ EXTRA_DIST = \ Makefile.nmake test/Makefile.nmake \ $(PLATFORM_DEPENDENT_SRC) -lib_LTLIBRARIES = libevent.la libevent_core.la libevent_extra.la +LIBEVENT_LIBS_LA = libevent.la libevent_core.la libevent_extra.la if PTHREADS -lib_LTLIBRARIES += libevent_pthreads.la -pkgconfig_DATA += libevent_pthreads.pc +LIBEVENT_LIBS_LA += libevent_pthreads.la +LIBEVENT_PKGCONFIG += libevent_pthreads.pc endif if OPENSSL -lib_LTLIBRARIES += libevent_openssl.la -pkgconfig_DATA += libevent_openssl.pc +LIBEVENT_LIBS_LA += libevent_openssl.la +LIBEVENT_PKGCONFIG += libevent_openssl.pc +endif + +if INSTALL_LIBEVENT +lib_LTLIBRARIES = $(LIBEVENT_LIBS_LA) +pkgconfig_DATA = $(LIBEVENT_PKGCONFIG) +else +noinst_LTLIBRARIES = $(LIBEVENT_LIBS_LA) endif SUBDIRS = . include sample test diff --git a/configure.in b/configure.in index 12d94034..cc4eb6cb 100644 --- a/configure.in +++ b/configure.in @@ -25,6 +25,18 @@ AC_GNU_SOURCE AC_MINIX ]) +AC_CANONICAL_BUILD +AC_CANONICAL_HOST +dnl the 'build' machine is where we run configure and compile +dnl the 'host' machine is where the resulting stuff runs. + +#case "$host_os" in +# +# osf5*) +# CFLAGS="$CFLAGS -D_OSF_SOURCE" +# ;; +#esac + dnl Checks for programs. AC_PROG_CC AC_PROG_INSTALL @@ -55,6 +67,16 @@ AC_ARG_ENABLE(openssl, AC_ARG_ENABLE(debug-mode, AS_HELP_STRING(--disable-debug-mode, disable support for running in debug mode), [], [enable_debug_mode=yes]) +AC_ARG_ENABLE([libevent-install], + AS_HELP_STRING([--disable-libevent-install, disable installation of libevent]), + [], [enable_libevent_install=yes]) +AC_ARG_ENABLE([libevent-regress], + AS_HELP_STRING([--disable-libevent-regress, skip regress in make check]), + [], [enable_libevent_regress=yes]) +AC_ARG_ENABLE([function-sections], + AS_HELP_STRING([--enable-function-sections, make static library allow smaller binaries with --gc-sections]), + [], [enable_function_sections=no]) + AC_PROG_LIBTOOL @@ -64,6 +86,14 @@ dnl the command line with --enable-shared and --disable-shared. dnl AC_DISABLE_SHARED AC_SUBST(LIBTOOL_DEPS) +AM_CONDITIONAL([BUILD_REGRESS], [test "$enable_libevent_regress" = "yes"]) +if test "$enable_libevent_regress" = "yes" ; then + CHECK_REGRESS=regress +else + CHECK_REGRESS= +fi +AC_SUBST([CHECK_REGRESS]) + dnl Checks for libraries. AC_SEARCH_LIBS([inet_ntoa], [nsl]) AC_SEARCH_LIBS([socket], [socket]) @@ -71,6 +101,9 @@ AC_SEARCH_LIBS([inet_aton], [resolv]) AC_SEARCH_LIBS([clock_gettime], [rt]) AC_SEARCH_LIBS([sendfile], [sendfile]) +AC_CHECK_HEADERS([zlib.h]) + +if test "x$ac_cv_header_zlib_h" = "xyes"; then dnl Determine if we have zlib for regression tests dnl Don't put this one in LIBS save_LIBS="$LIBS" @@ -83,6 +116,7 @@ AC_SEARCH_LIBS([inflateEnd], [z], AC_DEFINE(HAVE_LIBZ, 1, [Define if the system has zlib])]) LIBS="$save_LIBS" AC_SUBST(ZLIB_LIBS) +fi AM_CONDITIONAL(ZLIB_REGRESS, [test "$have_zlib" = "yes"]) dnl See if we have openssl. This doesn't go in LIBS either. @@ -101,7 +135,7 @@ fi dnl Checks for header files. AC_HEADER_STDC -AC_CHECK_HEADERS(fcntl.h stdarg.h inttypes.h stdint.h stddef.h poll.h unistd.h sys/epoll.h sys/time.h sys/queue.h sys/event.h sys/param.h sys/ioctl.h sys/select.h sys/devpoll.h port.h netinet/in.h netinet/in6.h sys/socket.h sys/uio.h arpa/inet.h sys/eventfd.h sys/mman.h sys/sendfile.h sys/wait.h netdb.h) +AC_CHECK_HEADERS([fcntl.h stdarg.h inttypes.h stdint.h stddef.h poll.h unistd.h sys/epoll.h sys/time.h sys/queue.h sys/event.h sys/param.h sys/ioctl.h sys/select.h sys/devpoll.h port.h netinet/in.h netinet/in6.h sys/socket.h sys/uio.h arpa/inet.h sys/eventfd.h sys/mman.h sys/sendfile.h sys/wait.h netdb.h]) AC_CHECK_HEADERS(sys/sysctl.h, [], [], [ #ifdef HAVE_SYS_PARAM_H #include @@ -210,10 +244,32 @@ AC_C_INLINE AC_HEADER_TIME dnl Checks for library functions. -AC_CHECK_FUNCS(gettimeofday vasprintf fcntl clock_gettime strtok_r strsep getaddrinfo getnameinfo strlcpy inet_ntop inet_pton signal sigaction strtoll inet_aton pipe eventfd sendfile mmap splice arc4random arc4random_buf issetugid geteuid getegid getservbyname getprotobynumber setenv unsetenv putenv) +AC_CHECK_FUNCS([gettimeofday vasprintf fcntl clock_gettime strtok_r strsep]) +AC_CHECK_FUNCS([getnameinfo strlcpy inet_ntop inet_pton signal sigaction strtoll inet_aton pipe eventfd sendfile mmap splice arc4random arc4random_buf issetugid geteuid getegid getprotobynumber setenv unsetenv putenv]) -if test "$ac_cv_func_getaddrinfo" != "yes" ; then +AC_CACHE_CHECK( + [for getaddrinfo], + [libevent_cv_getaddrinfo], + [AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[ + #ifdef HAVE_NETDB_H + #include + #endif + ]], + [[ + getaddrinfo; + ]] + )], + [libevent_cv_getaddrinfo=yes], + [libevent_cv_getaddrinfo=no] + )] +) +if test "$libevent_cv_getaddrinfo" = "yes" ; then + AC_DEFINE([HAVE_GETADDRINFO], [1], [Do we have getaddrinfo()?]) +else +AC_CHECK_FUNCS([getservbyname]) # Check for gethostbyname_r in all its glorious incompatible versions. # (This is cut-and-pasted from Tor, which based its logic on # Python's configure.in.) @@ -613,5 +669,39 @@ if test x$enable_gcc_warnings = xyes && test "$GCC" = "yes"; then fi +LIBEVENT_GC_SECTIONS= +if test "$GCC" = yes && test "$enable_function_sections" = yes ; then + AC_CACHE_CHECK( + [if linker supports omitting unused code and data], + [libevent_cv_gc_sections_works], + [ + origCFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -Wl,--gc-sections" + AC_LINK_IFELSE( + [AC_LANG_PROGRAM([[]], [[]])], + [ + if grep gc-sections conftest.err ; then + libevent_cv_gc_sections_works=no + else + libevent_cv_gc_sections_works=yes + fi + ], + [libevent_cv_gc_sections_works=no] + ) + CFLAGS="$origCFLAGS" + AS_UNSET([origCFLAGS]) + ] + ) + case "$libevent_cv_gc_sections_works" in + yes) + CFLAGS="-ffunction-sections -fdata-sections $CFLAGS" + LIBEVENT_GC_SECTIONS="-Wl,--gc-sections" + ;; + esac +fi +AC_SUBST([LIBEVENT_GC_SECTIONS]) + +AM_CONDITIONAL([INSTALL_LIBEVENT], [test "$enable_libevent_install" = "yes"]) + AC_CONFIG_FILES( [libevent.pc libevent_openssl.pc libevent_pthreads.pc] ) AC_OUTPUT(Makefile include/Makefile test/Makefile sample/Makefile) diff --git a/http.c b/http.c index b03176b6..1c51b4b3 100644 --- a/http.c +++ b/http.c @@ -57,6 +57,9 @@ #ifdef _EVENT_HAVE_NETINET_IN_H #include #endif +#ifdef _EVENT_HAVE_ARPA_INET_H +#include +#endif #ifdef _EVENT_HAVE_NETDB_H #include #endif diff --git a/include/event2/event.h b/include/event2/event.h index 5a3bbf32..09502fd6 100644 --- a/include/event2/event.h +++ b/include/event2/event.h @@ -107,6 +107,10 @@ int event_reinit(struct event_base *base); /** Threadsafe event dispatching loop. + This loop will run the event base until either there are no more added + events, or until something calls event_base_loopbreak() or + evenet_base_loopexit(). + @param eb the event_base structure returned by event_init() @see event_init(), event_dispatch() */ @@ -322,7 +326,7 @@ void event_set_fatal_callback(event_fatal_cb cb); int event_base_set(struct event_base *, struct event *); /** - event_loop() flags + event_base_loop() flags */ /*@{*/ /** Block until we have an active event, then exit once all active events @@ -338,6 +342,11 @@ int event_base_set(struct event_base *, struct event *); This is a more flexible version of event_base_dispatch(). + By default, this loop will run the event base until either there are no more + added events, or until something calls event_base_loopbreak() or + evenet_base_loopexit(). You can override this behavior with the 'flags' + argument. + @param eb the event_base structure returned by event_init() @param flags any combination of EVLOOP_ONCE | EVLOOP_NONBLOCK @return 0 if successful, -1 if an error occurred, or 1 if no events were diff --git a/sample/Makefile.am b/sample/Makefile.am index 0071d26f..86f4811d 100644 --- a/sample/Makefile.am +++ b/sample/Makefile.am @@ -1,6 +1,6 @@ AUTOMAKE_OPTIONS = foreign no-dependencies -LDADD = ../libevent.la +LDADD = $(LIBEVENT_GC_SECTIONS) ../libevent.la AM_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/compat -I$(top_srcdir)/include -I../include noinst_PROGRAMS = event-test time-test signal-test dns-example hello-world http-server diff --git a/sample/dns-example.c b/sample/dns-example.c index 55318215..439a486a 100644 --- a/sample/dns-example.c +++ b/sample/dns-example.c @@ -7,6 +7,9 @@ #include +/* Compatibility for possible missing IPv6 declarations */ +#include "../ipv6-internal.h" + #include #ifdef WIN32 diff --git a/sample/hello-world.c b/sample/hello-world.c index 90df85f7..d40af529 100644 --- a/sample/hello-world.c +++ b/sample/hello-world.c @@ -13,6 +13,9 @@ #include #ifndef WIN32 #include +# ifdef _XOPEN_SOURCE_EXTENDED +# include +# endif #include #endif diff --git a/sample/http-server.c b/sample/http-server.c index f9e84d1c..d5212c51 100644 --- a/sample/http-server.c +++ b/sample/http-server.c @@ -36,8 +36,14 @@ #ifdef _EVENT_HAVE_NETINET_IN_H #include +# ifdef _XOPEN_SOURCE_EXTENDED +# include +# endif #endif +/* Compatibility for possible missing IPv6 declarations */ +#include "../util-internal.h" + #ifdef WIN32 #define stat _stat #define fstat _fstat diff --git a/test/Makefile.am b/test/Makefile.am index 97682fb4..60dd4972 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,17 +1,22 @@ AUTOMAKE_OPTIONS = foreign -AM_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/compat -I$(top_srcdir)/include -I../include -DTINYTEST_LOCAL +AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/compat -I$(top_srcdir)/include -I../include -DTINYTEST_LOCAL EXTRA_DIST = regress.rpc regress.gen.h regress.gen.c test.sh -noinst_PROGRAMS = test-init test-eof test-weof test-time regress \ +noinst_PROGRAMS = test-init test-eof test-weof test-time @CHECK_REGRESS@ \ bench bench_cascade bench_http bench_httpclient test-ratelim \ test-changelist +EXTRA_PROGRAMS = regress noinst_HEADERS = tinytest.h tinytest_macros.h regress.h tinytest_local.h TESTS = $(top_srcdir)/test/test.sh -BUILT_SOURCES = regress.gen.c regress.gen.h +BUILT_SOURCES = +if BUILD_REGRESS +BUILT_SOURCES += regress.gen.c regress.gen.h +endif + test_init_SOURCES = test-init.c test_init_LDADD = ../libevent_core.la test_eof_SOURCES = test-eof.c @@ -45,7 +50,7 @@ if BUILD_WIN32 regress_SOURCES += regress_iocp.c endif -regress_LDADD = ../libevent.la $(PTHREAD_LIBS) $(ZLIB_LIBS) +regress_LDADD = $(LIBEVENT_GC_SECTIONS) ../libevent.la $(PTHREAD_LIBS) $(ZLIB_LIBS) regress_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/compat \ -I$(top_srcdir)/include -I../include $(PTHREAD_CFLAGS) $(ZLIB_CFLAGS) regress_LDFLAGS = $(PTHREAD_CFLAGS) @@ -56,13 +61,13 @@ regress_LDADD += ../libevent_openssl.la -lcrypto -lssl endif bench_SOURCES = bench.c -bench_LDADD = ../libevent.la +bench_LDADD = $(LIBEVENT_GC_SECTIONS) ../libevent.la bench_cascade_SOURCES = bench_cascade.c -bench_cascade_LDADD = ../libevent.la +bench_cascade_LDADD = $(LIBEVENT_GC_SECTIONS) ../libevent.la bench_http_SOURCES = bench_http.c -bench_http_LDADD = ../libevent.la +bench_http_LDADD = $(LIBEVENT_GC_SECTIONS) ../libevent.la bench_httpclient_SOURCES = bench_httpclient.c -bench_httpclient_LDADD = ../libevent_core.la +bench_httpclient_LDADD = $(LIBEVENT_GC_SECTIONS) ../libevent_core.la regress.gen.c regress.gen.h: regress.rpc $(top_srcdir)/event_rpcgen.py $(top_srcdir)/event_rpcgen.py $(srcdir)/regress.rpc || echo "No Python installed" diff --git a/test/bench_httpclient.c b/test/bench_httpclient.c index 19f025f1..f0888e6c 100644 --- a/test/bench_httpclient.c +++ b/test/bench_httpclient.c @@ -31,6 +31,9 @@ #else #include #include +# ifdef _XOPEN_SOURCE_EXTENDED +# include +# endif #endif #include #include diff --git a/test/regress_dns.c b/test/regress_dns.c index 255f613a..086fd429 100644 --- a/test/regress_dns.c +++ b/test/regress_dns.c @@ -71,6 +71,8 @@ #include "regress.h" #include "regress_testutils.h" +#include "../util-internal.h" + static int dns_ok = 0; static int dns_got_cancel = 0; static int dns_err = 0; diff --git a/test/regress_listener.c b/test/regress_listener.c index 1438f3aa..44fee7f4 100644 --- a/test/regress_listener.c +++ b/test/regress_listener.c @@ -34,6 +34,9 @@ #ifndef WIN32 #include #include +# ifdef _XOPEN_SOURCE_EXTENDED +# include +# endif #include #endif diff --git a/test/regress_testutils.c b/test/regress_testutils.c index b5bef1ab..8902e631 100644 --- a/test/regress_testutils.c +++ b/test/regress_testutils.c @@ -68,6 +68,8 @@ #include "regress.h" #include "regress_testutils.h" +#include "../util-internal.h" + /* globals */ static struct evdns_server_port *dns_port; evutil_socket_t dns_sock = -1; diff --git a/test/test-eof.c b/test/test-eof.c index 90b40938..417476e8 100644 --- a/test/test-eof.c +++ b/test/test-eof.c @@ -32,6 +32,7 @@ int test_okay = 1; int called = 0; +struct timeval timeout = {60, 0}; static void read_cb(evutil_socket_t fd, short event, void *arg) @@ -39,6 +40,11 @@ read_cb(evutil_socket_t fd, short event, void *arg) char buf[256]; int len; + if (EV_TIMEOUT & event) { + printf("%s: Timeout!\n", __func__); + exit(1); + } + len = recv(fd, buf, sizeof(buf), 0); printf("%s: read %d%s\n", __func__, @@ -46,7 +52,7 @@ read_cb(evutil_socket_t fd, short event, void *arg) if (len) { if (!called) - event_add(arg, NULL); + event_add(arg, &timeout); } else if (called == 1) test_okay = 0; @@ -85,9 +91,9 @@ main(int argc, char **argv) event_init(); /* Initalize one event */ - event_set(&ev, pair[1], EV_READ, read_cb, &ev); + event_set(&ev, pair[1], EV_READ | EV_TIMEOUT, read_cb, &ev); - event_add(&ev, NULL); + event_add(&ev, &timeout); event_dispatch(); diff --git a/test/test-ratelim.c b/test/test-ratelim.c index 824434e0..bbbd7608 100644 --- a/test/test-ratelim.c +++ b/test/test-ratelim.c @@ -36,6 +36,9 @@ #else #include #include +# ifdef _XOPEN_SOURCE_EXTENDED +# include +# endif #endif #include @@ -46,6 +49,8 @@ #include "event2/listener.h" #include "event2/thread.h" +#include "../util-internal.h" + static int cfg_verbose = 0; static int cfg_help = 0; diff --git a/test/test.sh b/test/test.sh index 0054faee..08a4cddb 100755 --- a/test/test.sh +++ b/test/test.sh @@ -9,9 +9,9 @@ fi # /bin/echo is a little more likely to support -n than sh's builtin echo, # printf is even more likely -if test "`printf hello 2>&1`" = "hello" +if test "`printf %s hello 2>&1`" = "hello" then - ECHO_N="printf" + ECHO_N="printf %s" else if test -x /bin/echo then @@ -97,6 +97,7 @@ run_tests () { announce FAILED ; FAILED=yes fi + test -x $TEST_DIR/regress || return announce_n " regress: " if test "$TEST_OUTPUT_FILE" = "/dev/null" ; then