diff options
Diffstat (limited to 'third_party/libevent/test')
-rw-r--r-- | third_party/libevent/test/Makefile.in | 22 | ||||
-rw-r--r-- | third_party/libevent/test/bench.c | 9 | ||||
-rw-r--r-- | third_party/libevent/test/regress.c | 114 | ||||
-rw-r--r-- | third_party/libevent/test/regress.gen.c | 42 | ||||
-rw-r--r-- | third_party/libevent/test/regress.gen.h | 69 | ||||
-rw-r--r-- | third_party/libevent/test/regress_dns.c | 6 | ||||
-rw-r--r-- | third_party/libevent/test/regress_http.c | 122 | ||||
-rw-r--r-- | third_party/libevent/test/regress_rpc.c | 2 | ||||
-rw-r--r-- | third_party/libevent/test/test-eof.c | 8 | ||||
-rw-r--r-- | third_party/libevent/test/test-init.c | 7 | ||||
-rw-r--r-- | third_party/libevent/test/test-time.c | 7 | ||||
-rw-r--r-- | third_party/libevent/test/test-weof.c | 8 |
12 files changed, 332 insertions, 84 deletions
diff --git a/third_party/libevent/test/Makefile.in b/third_party/libevent/test/Makefile.in index a109603..c2d5b31 100644 --- a/third_party/libevent/test/Makefile.in +++ b/third_party/libevent/test/Makefile.in @@ -1,8 +1,8 @@ -# Makefile.in generated by automake 1.10 from Makefile.am. +# Makefile.in generated by automake 1.10.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -65,7 +65,7 @@ test_time_DEPENDENCIES = ../libevent_core.la am_test_weof_OBJECTS = test-weof.$(OBJEXT) test_weof_OBJECTS = $(am_test_weof_OBJECTS) test_weof_DEPENDENCIES = ../libevent_core.la -DEFAULT_INCLUDES = -I. -I$(top_builddir)@am__isrc@ +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = am__depfiles_maybe = COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ @@ -103,6 +103,7 @@ CXXFLAGS = @CXXFLAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ ECHO = @ECHO@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ @@ -126,6 +127,7 @@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAKEINFO = @MAKEINFO@ MKDIR_P = @MKDIR_P@ +NMEDIT = @NMEDIT@ OBJEXT = @OBJEXT@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ @@ -189,6 +191,7 @@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = foreign no-dependencies @@ -297,8 +300,8 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ + $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ mkid -fID $$unique tags: TAGS @@ -310,8 +313,8 @@ TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ @@ -321,13 +324,12 @@ ctags: CTAGS CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) tags=; \ - here=`pwd`; \ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ test -z "$(CTAGS_ARGS)$$tags$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$tags $$unique diff --git a/third_party/libevent/test/bench.c b/third_party/libevent/test/bench.c index 48fd32a..c976932 100644 --- a/third_party/libevent/test/bench.c +++ b/third_party/libevent/test/bench.c @@ -44,7 +44,7 @@ #include <windows.h> #else #include <sys/socket.h> -#include <sys/signal.h> +#include <signal.h> #include <sys/resource.h> #endif #include <fcntl.h> @@ -63,12 +63,10 @@ static int *pipes; static int num_pipes, num_active, num_writes; static struct event *events; - - static void read_cb(int fd, short which, void *arg) { - int idx = (int) arg, widx = idx + 1; + long idx = (long) arg, widx = idx + 1; u_char ch; count += read(fd, &ch, sizeof(ch)); @@ -84,7 +82,8 @@ read_cb(int fd, short which, void *arg) static struct timeval * run_once(void) { - int *cp, i, space; + int *cp, space; + long i; static struct timeval ts, te; for (cp = pipes, i = 0; i < num_pipes; i++, cp += 2) { diff --git a/third_party/libevent/test/regress.c b/third_party/libevent/test/regress.c index e939d1d..0b7517d 100644 --- a/third_party/libevent/test/regress.c +++ b/third_party/libevent/test/regress.c @@ -43,7 +43,7 @@ #ifndef WIN32 #include <sys/socket.h> #include <sys/wait.h> -#include <sys/signal.h> +#include <signal.h> #include <unistd.h> #include <netdb.h> #endif @@ -95,6 +95,9 @@ simple_read_cb(int fd, short event, void *arg) char buf[256]; int len; + if (arg == NULL) + return; + len = read(fd, buf, sizeof(buf)); if (len) { @@ -113,6 +116,9 @@ simple_write_cb(int fd, short event, void *arg) { int len; + if (arg == NULL) + return; + len = write(fd, TEST1, strlen(TEST1) + 1); if (len == -1) test_ok = 0; @@ -195,6 +201,7 @@ timeout_cb(int fd, short event, void *arg) test_ok = 1; } +#ifndef WIN32 static void signal_cb_sa(int sig) { @@ -209,6 +216,7 @@ signal_cb(int fd, short event, void *arg) signal_del(ev); test_ok = 1; } +#endif struct both { struct event ev; @@ -304,6 +312,57 @@ cleanup_test(void) } static void +test_registerfds(void) +{ + int i, j; + int pair[2]; + struct event read_evs[512]; + struct event write_evs[512]; + + struct event_base *base = event_base_new(); + + fprintf(stdout, "Testing register fds: "); + + for (i = 0; i < 512; ++i) { + if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) { + /* run up to the limit of file descriptors */ + break; + } + event_set(&read_evs[i], pair[0], + EV_READ|EV_PERSIST, simple_read_cb, NULL); + event_base_set(base, &read_evs[i]); + event_add(&read_evs[i], NULL); + event_set(&write_evs[i], pair[1], + EV_WRITE|EV_PERSIST, simple_write_cb, NULL); + event_base_set(base, &write_evs[i]); + event_add(&write_evs[i], NULL); + + /* just loop once */ + event_base_loop(base, EVLOOP_ONCE); + } + + /* now delete everything */ + for (j = 0; j < i; ++j) { + event_del(&read_evs[j]); + event_del(&write_evs[j]); +#ifndef WIN32 + close(read_evs[j].ev_fd); + close(write_evs[j].ev_fd); +#else + CloseHandle((HANDLE)read_evs[j].ev_fd); + CloseHandle((HANDLE)write_evs[j].ev_fd); +#endif + + /* just loop once */ + event_base_loop(base, EVLOOP_ONCE); + } + + event_base_free(base); + + fprintf(stdout, "OK\n"); +} + +static void test_simpleread(void) { struct event ev; @@ -764,6 +823,52 @@ out: cleanup_test(); return; } + +static void +signal_cb_swp(int sig, short event, void *arg) +{ + called++; + if (called < 5) + raise(sig); + else + event_loopexit(NULL); +} +static void +timeout_cb_swp(int fd, short event, void *arg) +{ + if (called == -1) { + struct timeval tv = {5, 0}; + + called = 0; + evtimer_add((struct event *)arg, &tv); + raise(SIGUSR1); + return; + } + test_ok = 0; + event_loopexit(NULL); +} + +static void +test_signal_while_processing(void) +{ + struct event_base *base = event_init(); + struct event ev, ev_timer; + struct timeval tv = {0, 0}; + + setup_test("Receiving a signal while processing other signal: "); + + called = -1; + test_ok = 1; + signal_set(&ev, SIGUSR1, signal_cb_swp, NULL); + signal_add(&ev, NULL); + evtimer_set(&ev_timer, timeout_cb_swp, &ev_timer); + evtimer_add(&ev_timer, &tv); + event_dispatch(); + + event_base_free(base); + cleanup_test(); + return; +} #endif static void @@ -1515,11 +1620,17 @@ main (int argc, char **argv) err = WSAStartup( wVersionRequested, &wsaData ); #endif +#ifndef WIN32 + if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) + return (1); +#endif setvbuf(stdout, NULL, _IONBF, 0); /* Initalize the event library */ global_base = event_init(); + test_registerfds(); + test_evutil_strtoll(); /* use the global event base and need to be called first */ @@ -1584,6 +1695,7 @@ main (int argc, char **argv) test_signal_switchbase(); test_signal_restore(); test_signal_assert(); + test_signal_while_processing(); #endif return (0); diff --git a/third_party/libevent/test/regress.gen.c b/third_party/libevent/test/regress.gen.c index ff31096..0918fc0 100644 --- a/third_party/libevent/test/regress.gen.c +++ b/third_party/libevent/test/regress.gen.c @@ -4,12 +4,18 @@ */ #include <sys/types.h> +#ifdef _EVENT_HAVE_SYS_TIME_H #include <sys/time.h> +#endif #include <stdlib.h> #include <string.h> #include <assert.h> +#define EVENT_NO_STRUCT #include <event.h> +#ifdef _EVENT___func__ +#define __func__ _EVENT___func__ +#endif #include "./regress.gen.h" @@ -290,7 +296,7 @@ msg_marshal(struct evbuffer *evbuf, const struct msg *tmp){ int msg_unmarshal(struct msg *tmp, struct evbuffer *evbuf) { - uint32_t tag; + ev_uint32_t tag; while (EVBUFFER_LENGTH(evbuf) > 0) { if (evtag_peek(evbuf, &tag) == -1) return (-1); @@ -375,9 +381,9 @@ msg_complete(struct msg *msg) } int -evtag_unmarshal_msg(struct evbuffer *evbuf, uint32_t need_tag, struct msg *msg) +evtag_unmarshal_msg(struct evbuffer *evbuf, ev_uint32_t need_tag, struct msg *msg) { - uint32_t tag; + ev_uint32_t tag; int res = -1; struct evbuffer *tmp = evbuffer_new(); @@ -396,7 +402,7 @@ evtag_unmarshal_msg(struct evbuffer *evbuf, uint32_t need_tag, struct msg *msg) } void -evtag_marshal_msg(struct evbuffer *evbuf, uint32_t tag, const struct msg *msg) +evtag_marshal_msg(struct evbuffer *evbuf, ev_uint32_t tag, const struct msg *msg) { struct evbuffer *_buf = evbuffer_new(); assert(_buf != NULL); @@ -469,7 +475,7 @@ kill_action_assign(struct kill *msg, } int -kill_how_often_assign(struct kill *msg, const uint32_t value) +kill_how_often_assign(struct kill *msg, const ev_uint32_t value) { msg->how_often_set = 1; msg->how_often_data = value; @@ -495,7 +501,7 @@ kill_action_get(struct kill *msg, char * *value) } int -kill_how_often_get(struct kill *msg, uint32_t *value) +kill_how_often_get(struct kill *msg, ev_uint32_t *value) { if (msg->how_often_set != 1) return (-1); @@ -541,7 +547,7 @@ kill_marshal(struct evbuffer *evbuf, const struct kill *tmp){ int kill_unmarshal(struct kill *tmp, struct evbuffer *evbuf) { - uint32_t tag; + ev_uint32_t tag; while (EVBUFFER_LENGTH(evbuf) > 0) { if (evtag_peek(evbuf, &tag) == -1) return (-1); @@ -601,9 +607,9 @@ kill_complete(struct kill *msg) } int -evtag_unmarshal_kill(struct evbuffer *evbuf, uint32_t need_tag, struct kill *msg) +evtag_unmarshal_kill(struct evbuffer *evbuf, ev_uint32_t need_tag, struct kill *msg) { - uint32_t tag; + ev_uint32_t tag; int res = -1; struct evbuffer *tmp = evbuffer_new(); @@ -622,7 +628,7 @@ evtag_unmarshal_kill(struct evbuffer *evbuf, uint32_t need_tag, struct kill *msg } void -evtag_marshal_kill(struct evbuffer *evbuf, uint32_t tag, const struct kill *msg) +evtag_marshal_kill(struct evbuffer *evbuf, ev_uint32_t tag, const struct kill *msg) { struct evbuffer *_buf = evbuffer_new(); assert(_buf != NULL); @@ -684,7 +690,7 @@ run_how_assign(struct run *msg, } int -run_some_bytes_assign(struct run *msg, const uint8_t * value, uint32_t len) +run_some_bytes_assign(struct run *msg, const ev_uint8_t * value, ev_uint32_t len) { if (msg->some_bytes_data != NULL) free (msg->some_bytes_data); @@ -698,7 +704,7 @@ run_some_bytes_assign(struct run *msg, const uint8_t * value, uint32_t len) } int -run_fixed_bytes_assign(struct run *msg, const uint8_t *value) +run_fixed_bytes_assign(struct run *msg, const ev_uint8_t *value) { msg->fixed_bytes_set = 1; memcpy(msg->fixed_bytes_data, value, 24); @@ -715,7 +721,7 @@ run_how_get(struct run *msg, char * *value) } int -run_some_bytes_get(struct run *msg, uint8_t * *value, uint32_t *plen) +run_some_bytes_get(struct run *msg, ev_uint8_t * *value, ev_uint32_t *plen) { if (msg->some_bytes_set != 1) return (-1); @@ -725,7 +731,7 @@ run_some_bytes_get(struct run *msg, uint8_t * *value, uint32_t *plen) } int -run_fixed_bytes_get(struct run *msg, uint8_t **value) +run_fixed_bytes_get(struct run *msg, ev_uint8_t **value) { if (msg->fixed_bytes_set != 1) return (-1); @@ -773,7 +779,7 @@ run_marshal(struct evbuffer *evbuf, const struct run *tmp){ int run_unmarshal(struct run *tmp, struct evbuffer *evbuf) { - uint32_t tag; + ev_uint32_t tag; while (EVBUFFER_LENGTH(evbuf) > 0) { if (evtag_peek(evbuf, &tag) == -1) return (-1); @@ -839,9 +845,9 @@ run_complete(struct run *msg) } int -evtag_unmarshal_run(struct evbuffer *evbuf, uint32_t need_tag, struct run *msg) +evtag_unmarshal_run(struct evbuffer *evbuf, ev_uint32_t need_tag, struct run *msg) { - uint32_t tag; + ev_uint32_t tag; int res = -1; struct evbuffer *tmp = evbuffer_new(); @@ -860,7 +866,7 @@ evtag_unmarshal_run(struct evbuffer *evbuf, uint32_t need_tag, struct run *msg) } void -evtag_marshal_run(struct evbuffer *evbuf, uint32_t tag, const struct run *msg) +evtag_marshal_run(struct evbuffer *evbuf, ev_uint32_t tag, const struct run *msg) { struct evbuffer *_buf = evbuffer_new(); assert(_buf != NULL); diff --git a/third_party/libevent/test/regress.gen.h b/third_party/libevent/test/regress.gen.h index 4232b33..b1feacd 100644 --- a/third_party/libevent/test/regress.gen.h +++ b/third_party/libevent/test/regress.gen.h @@ -10,8 +10,13 @@ #include <stdint.h> #endif #define EVTAG_HAS(msg, member) ((msg)->member##_set == 1) +#ifdef __GNUC__ #define EVTAG_ASSIGN(msg, member, args...) (*(msg)->base->member##_assign)(msg, ## args) #define EVTAG_GET(msg, member, args...) (*(msg)->base->member##_get)(msg, ## args) +#else +#define EVTAG_ASSIGN(msg, member, ...) (*(msg)->base->member##_assign)(msg, ## __VA_ARGS__) +#define EVTAG_GET(msg, member, ...) (*(msg)->base->member##_get)(msg, ## __VA_ARGS__) +#endif #define EVTAG_ADD(msg, member) (*(msg)->base->member##_add)(msg) #define EVTAG_LEN(msg, member) ((msg)->member##_length) @@ -51,10 +56,10 @@ struct msg { int run_length; int run_num_allocated; - uint8_t from_name_set; - uint8_t to_name_set; - uint8_t attack_set; - uint8_t run_set; + ev_uint8_t from_name_set; + ev_uint8_t to_name_set; + ev_uint8_t attack_set; + ev_uint8_t run_set; }; struct msg *msg_new(void); @@ -63,9 +68,9 @@ void msg_clear(struct msg *); void msg_marshal(struct evbuffer *, const struct msg *); int msg_unmarshal(struct msg *, struct evbuffer *); int msg_complete(struct msg *); -void evtag_marshal_msg(struct evbuffer *, uint32_t, +void evtag_marshal_msg(struct evbuffer *, ev_uint32_t, const struct msg *); -int evtag_unmarshal_msg(struct evbuffer *, uint32_t, +int evtag_unmarshal_msg(struct evbuffer *, ev_uint32_t, struct msg *); int msg_from_name_assign(struct msg *, const char *); int msg_from_name_get(struct msg *, char * *); @@ -92,8 +97,8 @@ struct kill_access_ { int (*weapon_get)(struct kill *, char * *); int (*action_assign)(struct kill *, const char *); int (*action_get)(struct kill *, char * *); - int (*how_often_assign)(struct kill *, const uint32_t); - int (*how_often_get)(struct kill *, uint32_t *); + int (*how_often_assign)(struct kill *, const ev_uint32_t); + int (*how_often_get)(struct kill *, ev_uint32_t *); }; struct kill { @@ -101,11 +106,11 @@ struct kill { char *weapon_data; char *action_data; - uint32_t how_often_data; + ev_uint32_t how_often_data; - uint8_t weapon_set; - uint8_t action_set; - uint8_t how_often_set; + ev_uint8_t weapon_set; + ev_uint8_t action_set; + ev_uint8_t how_often_set; }; struct kill *kill_new(void); @@ -114,16 +119,16 @@ void kill_clear(struct kill *); void kill_marshal(struct evbuffer *, const struct kill *); int kill_unmarshal(struct kill *, struct evbuffer *); int kill_complete(struct kill *); -void evtag_marshal_kill(struct evbuffer *, uint32_t, +void evtag_marshal_kill(struct evbuffer *, ev_uint32_t, const struct kill *); -int evtag_unmarshal_kill(struct evbuffer *, uint32_t, +int evtag_unmarshal_kill(struct evbuffer *, ev_uint32_t, struct kill *); int kill_weapon_assign(struct kill *, const char *); int kill_weapon_get(struct kill *, char * *); int kill_action_assign(struct kill *, const char *); int kill_action_get(struct kill *, char * *); -int kill_how_often_assign(struct kill *, const uint32_t); -int kill_how_often_get(struct kill *, uint32_t *); +int kill_how_often_assign(struct kill *, const ev_uint32_t); +int kill_how_often_get(struct kill *, ev_uint32_t *); /* --- kill done --- */ /* Tag definition for run */ @@ -138,23 +143,23 @@ enum run_ { struct run_access_ { int (*how_assign)(struct run *, const char *); int (*how_get)(struct run *, char * *); - int (*some_bytes_assign)(struct run *, const uint8_t *, uint32_t); - int (*some_bytes_get)(struct run *, uint8_t * *, uint32_t *); - int (*fixed_bytes_assign)(struct run *, const uint8_t *); - int (*fixed_bytes_get)(struct run *, uint8_t **); + int (*some_bytes_assign)(struct run *, const ev_uint8_t *, ev_uint32_t); + int (*some_bytes_get)(struct run *, ev_uint8_t * *, ev_uint32_t *); + int (*fixed_bytes_assign)(struct run *, const ev_uint8_t *); + int (*fixed_bytes_get)(struct run *, ev_uint8_t **); }; struct run { struct run_access_ *base; char *how_data; - uint8_t *some_bytes_data; - uint32_t some_bytes_length; - uint8_t fixed_bytes_data[24]; + ev_uint8_t *some_bytes_data; + ev_uint32_t some_bytes_length; + ev_uint8_t fixed_bytes_data[24]; - uint8_t how_set; - uint8_t some_bytes_set; - uint8_t fixed_bytes_set; + ev_uint8_t how_set; + ev_uint8_t some_bytes_set; + ev_uint8_t fixed_bytes_set; }; struct run *run_new(void); @@ -163,16 +168,16 @@ void run_clear(struct run *); void run_marshal(struct evbuffer *, const struct run *); int run_unmarshal(struct run *, struct evbuffer *); int run_complete(struct run *); -void evtag_marshal_run(struct evbuffer *, uint32_t, +void evtag_marshal_run(struct evbuffer *, ev_uint32_t, const struct run *); -int evtag_unmarshal_run(struct evbuffer *, uint32_t, +int evtag_unmarshal_run(struct evbuffer *, ev_uint32_t, struct run *); int run_how_assign(struct run *, const char *); int run_how_get(struct run *, char * *); -int run_some_bytes_assign(struct run *, const uint8_t *, uint32_t); -int run_some_bytes_get(struct run *, uint8_t * *, uint32_t *); -int run_fixed_bytes_assign(struct run *, const uint8_t *); -int run_fixed_bytes_get(struct run *, uint8_t **); +int run_some_bytes_assign(struct run *, const ev_uint8_t *, ev_uint32_t); +int run_some_bytes_get(struct run *, ev_uint8_t * *, ev_uint32_t *); +int run_fixed_bytes_assign(struct run *, const ev_uint8_t *); +int run_fixed_bytes_get(struct run *, ev_uint8_t **); /* --- run done --- */ #endif /* ___REGRESS_RPC_ */ diff --git a/third_party/libevent/test/regress_dns.c b/third_party/libevent/test/regress_dns.c index 8191192..129cdad 100644 --- a/third_party/libevent/test/regress_dns.c +++ b/third_party/libevent/test/regress_dns.c @@ -42,7 +42,7 @@ #include <sys/queue.h> #ifndef WIN32 #include <sys/socket.h> -#include <sys/signal.h> +#include <signal.h> #include <netinet/in.h> #include <arpa/inet.h> #include <unistd.h> @@ -89,7 +89,7 @@ dns_gethostbyname_cb(int result, char type, int count, int ttl, switch (type) { case DNS_IPv6_AAAA: { -#if defined(HAVE_STRUCT_IN6_ADDR) && defined(HAVE_INET_NTOP) +#if defined(HAVE_STRUCT_IN6_ADDR) && defined(HAVE_INET_NTOP) && defined(INET6_ADDRSTRLEN) struct in6_addr *in6_addrs = addresses; char buf[INET6_ADDRSTRLEN+1]; int i; @@ -258,7 +258,7 @@ dns_server_gethostbyname_cb(int result, char type, int count, int ttl, break; } case DNS_IPv6_AAAA: { -#if defined (HAVE_STRUCT_IN6_ADDR) && defined(HAVE_INET_NTOP) +#if defined (HAVE_STRUCT_IN6_ADDR) && defined(HAVE_INET_NTOP) && defined(INET6_ADDRSTRLEN) struct in6_addr *in6_addrs = addresses; char buf[INET6_ADDRSTRLEN+1]; if (memcmp(&in6_addrs[0].s6_addr, "abcdefghijklmnop", 16) diff --git a/third_party/libevent/test/regress_http.c b/third_party/libevent/test/regress_http.c index 7dc763c..1e2a1eb 100644 --- a/third_party/libevent/test/regress_http.c +++ b/third_party/libevent/test/regress_http.c @@ -42,7 +42,7 @@ #include <sys/queue.h> #ifndef WIN32 #include <sys/socket.h> -#include <sys/signal.h> +#include <signal.h> #include <unistd.h> #include <netdb.h> #endif @@ -70,6 +70,7 @@ void http_basic_cb(struct evhttp_request *req, void *arg); static void http_chunked_cb(struct evhttp_request *req, void *arg); void http_post_cb(struct evhttp_request *req, void *arg); void http_dispatcher_cb(struct evhttp_request *req, void *arg); +static void http_large_delay_cb(struct evhttp_request *req, void *arg); static struct evhttp * http_setup(short *pport, struct event_base *base) @@ -94,6 +95,7 @@ http_setup(short *pport, struct event_base *base) evhttp_set_cb(myhttp, "/test", http_basic_cb, NULL); evhttp_set_cb(myhttp, "/chunked", http_chunked_cb, NULL); evhttp_set_cb(myhttp, "/postit", http_post_cb, NULL); + evhttp_set_cb(myhttp, "/largedelay", http_large_delay_cb, NULL); evhttp_set_cb(myhttp, "/", http_dispatcher_cb, NULL); *pport = port; @@ -375,6 +377,31 @@ http_basic_test(void) fprintf(stdout, "OK\n"); } +static struct evhttp_connection *delayed_client; + +static void +http_delay_reply(int fd, short what, void *arg) +{ + struct evhttp_request *req = arg; + + evhttp_send_reply(req, HTTP_OK, "Everything is fine", NULL); + + ++test_ok; +} + +static void +http_large_delay_cb(struct evhttp_request *req, void *arg) +{ + struct timeval tv; + timerclear(&tv); + tv.tv_sec = 3; + + event_once(-1, EV_TIMEOUT, http_delay_reply, req, &tv); + + /* here we close the client connection which will cause an EOF */ + evhttp_connection_fail(delayed_client, EVCON_HTTP_EOF); +} + void http_request_done(struct evhttp_request *, void *); void http_request_empty_done(struct evhttp_request *, void *); @@ -819,6 +846,7 @@ http_failure_test(void) static void close_detect_done(struct evhttp_request *req, void *arg) { + struct timeval tv; if (req == NULL || req->response_code != HTTP_OK) { fprintf(stderr, "FAILED\n"); @@ -826,7 +854,11 @@ close_detect_done(struct evhttp_request *req, void *arg) } test_ok = 1; - event_loopexit(NULL); + + timerclear(&tv); + tv.tv_sec = 3; /* longer than the http time out */ + + event_loopexit(&tv); } static void @@ -853,7 +885,7 @@ close_detect_cb(struct evhttp_request *req, void *arg) struct evhttp_connection *evcon = arg; struct timeval tv; - if (req->response_code != HTTP_OK) { + if (req != NULL && req->response_code != HTTP_OK) { fprintf(stderr, "FAILED\n"); exit(1); @@ -868,14 +900,15 @@ close_detect_cb(struct evhttp_request *req, void *arg) static void -http_close_detection(void) +http_close_detection(int with_delay) { short port = -1; struct evhttp_connection *evcon = NULL; struct evhttp_request *req = NULL; test_ok = 0; - fprintf(stdout, "Testing Connection Close Detection: "); + fprintf(stdout, "Testing Connection Close Detection%s: ", + with_delay ? " (with delay)" : ""); http = http_setup(&port, NULL); @@ -888,6 +921,8 @@ http_close_detection(void) exit(1); } + delayed_client = evcon; + /* * At this point, we want to schedule a request to the HTTP * server using our make request method. @@ -899,7 +934,8 @@ http_close_detection(void) evhttp_add_header(req->output_headers, "Host", "somehost"); /* We give ownership of the request to the connection */ - if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test") == -1) { + if (evhttp_make_request(evcon, + req, EVHTTP_REQ_GET, with_delay ? "/largedelay" : "/test") == -1) { fprintf(stdout, "FAILED\n"); exit(1); } @@ -911,6 +947,12 @@ http_close_detection(void) exit(1); } + /* at this point, the http server should have no connection */ + if (TAILQ_FIRST(&http->connections) != NULL) { + fprintf(stdout, "FAILED (left connections)\n"); + exit(1); + } + evhttp_connection_free(evcon); evhttp_free(http); @@ -953,13 +995,16 @@ http_bad_header_test(void) if (evhttp_add_header(&headers, "One\r", "Two") != -1) goto fail; - + if (evhttp_add_header(&headers, "One", "Two") != 0) + goto fail; + if (evhttp_add_header(&headers, "One", "Two\r\n Three") != 0) + goto fail; + if (evhttp_add_header(&headers, "One\r", "Two") != -1) + goto fail; if (evhttp_add_header(&headers, "One\n", "Two") != -1) goto fail; - if (evhttp_add_header(&headers, "One", "Two\r") != -1) goto fail; - if (evhttp_add_header(&headers, "One", "Two\n") != -1) goto fail; @@ -972,6 +1017,61 @@ fail: exit(1); } +static int validate_header( + const struct evkeyvalq* headers, + const char *key, const char *value) +{ + const char *real_val = evhttp_find_header(headers, key); + if (real_val == NULL) + return (-1); + if (strcmp(real_val, value) != 0) + return (-1); + return (0); +} + +static void +http_parse_query_test(void) +{ + struct evkeyvalq headers; + + fprintf(stdout, "Testing HTTP query parsing: "); + + TAILQ_INIT(&headers); + + evhttp_parse_query("http://www.test.com/?q=test", &headers); + if (validate_header(&headers, "q", "test") != 0) + goto fail; + evhttp_clear_headers(&headers); + + evhttp_parse_query("http://www.test.com/?q=test&foo=bar", &headers); + if (validate_header(&headers, "q", "test") != 0) + goto fail; + if (validate_header(&headers, "foo", "bar") != 0) + goto fail; + evhttp_clear_headers(&headers); + + evhttp_parse_query("http://www.test.com/?q=test+foo", &headers); + if (validate_header(&headers, "q", "test foo") != 0) + goto fail; + evhttp_clear_headers(&headers); + + evhttp_parse_query("http://www.test.com/?q=test%0Afoo", &headers); + if (validate_header(&headers, "q", "test\nfoo") != 0) + goto fail; + evhttp_clear_headers(&headers); + + evhttp_parse_query("http://www.test.com/?q=test%0Dfoo", &headers); + if (validate_header(&headers, "q", "test\rfoo") != 0) + goto fail; + evhttp_clear_headers(&headers); + + fprintf(stdout, "OK\n"); + return; +fail: + fprintf(stdout, "FAILED\n"); + exit(1); +} + static void http_base_test(void) { @@ -1358,10 +1458,12 @@ http_suite(void) { http_base_test(); http_bad_header_test(); + http_parse_query_test(); http_basic_test(); http_connection_test(0 /* not-persistent */); http_connection_test(1 /* persistent */); - http_close_detection(); + http_close_detection(0 /* with delay */); + http_close_detection(1 /* with delay */); http_post_test(); http_failure_test(); http_highport_test(); diff --git a/third_party/libevent/test/regress_rpc.c b/third_party/libevent/test/regress_rpc.c index c80fb9d..7609347 100644 --- a/third_party/libevent/test/regress_rpc.c +++ b/third_party/libevent/test/regress_rpc.c @@ -42,7 +42,7 @@ #include <sys/queue.h> #ifndef WIN32 #include <sys/socket.h> -#include <sys/signal.h> +#include <signal.h> #include <unistd.h> #include <netdb.h> #endif diff --git a/third_party/libevent/test/test-eof.c b/third_party/libevent/test/test-eof.c index 4fc1a19..3264a7b 100644 --- a/third_party/libevent/test/test-eof.c +++ b/third_party/libevent/test/test-eof.c @@ -12,7 +12,9 @@ #endif #include <sys/types.h> #include <sys/stat.h> +#ifdef HAVE_SYS_TIME_H #include <sys/time.h> +#endif #ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif @@ -20,7 +22,9 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#ifdef HAVE_UNISTD_H #include <unistd.h> +#endif #include <errno.h> #include <event.h> @@ -35,7 +39,7 @@ read_cb(int fd, short event, void *arg) char buf[256]; int len; - len = read(fd, buf, sizeof(buf)); + len = recv(fd, buf, sizeof(buf), 0); printf("%s: read %d%s\n", __func__, len, len ? "" : " - means EOF"); @@ -64,7 +68,7 @@ main (int argc, char **argv) return (1); - write(pair[0], test, strlen(test)+1); + send(pair[0], test, strlen(test)+1, 0); shutdown(pair[0], SHUT_WR); /* Initalize the event library */ diff --git a/third_party/libevent/test/test-init.c b/third_party/libevent/test/test-init.c index c368715..d60aa36 100644 --- a/third_party/libevent/test/test-init.c +++ b/third_party/libevent/test/test-init.c @@ -6,10 +6,15 @@ #include "config.h" #endif +#ifdef WIN32 +#include <winsock2.h> +#endif #include <sys/types.h> #include <sys/stat.h> +#ifdef HAVE_SYS_TIME_H #include <sys/time.h> +#endif #ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif @@ -17,7 +22,9 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#ifdef HAVE_UNISTD_H #include <unistd.h> +#endif #include <errno.h> #include <event.h> diff --git a/third_party/libevent/test/test-time.c b/third_party/libevent/test/test-time.c index a847d55..703bc32 100644 --- a/third_party/libevent/test/test-time.c +++ b/third_party/libevent/test/test-time.c @@ -6,15 +6,22 @@ #include "config.h" #endif +#ifdef WIN32 +#include <winsock2.h> +#endif #include <sys/types.h> #include <sys/stat.h> +#ifdef HAVE_SYS_TIME_H #include <sys/time.h> +#endif #include <fcntl.h> #include <stdlib.h> #include <stdio.h> #include <string.h> +#ifdef HAVE_UNISTD_H #include <unistd.h> +#endif #include <errno.h> #include <event.h> diff --git a/third_party/libevent/test/test-weof.c b/third_party/libevent/test/test-weof.c index 5d87ceb..7fd6c8b 100644 --- a/third_party/libevent/test/test-weof.c +++ b/third_party/libevent/test/test-weof.c @@ -12,7 +12,9 @@ #endif #include <sys/types.h> #include <sys/stat.h> +#ifdef HAVE_SYS_TIME_H #include <sys/time.h> +#endif #ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif @@ -21,7 +23,9 @@ #include <stdio.h> #include <string.h> #include <signal.h> +#ifdef HAVE_UNISTD_H #include <unistd.h> +#endif #include <errno.h> #include <event.h> @@ -37,7 +41,7 @@ write_cb(int fd, short event, void *arg) const char *test = "test string"; int len; - len = write(fd, test, strlen(test) + 1); + len = send(fd, test, strlen(test) + 1, 0); printf("%s: write %d%s\n", __func__, len, len ? "" : " - means EOF"); @@ -45,7 +49,7 @@ write_cb(int fd, short event, void *arg) if (len > 0) { if (!called) event_add(arg, NULL); - close(pair[0]); + EVUTIL_CLOSESOCKET(pair[0]); } else if (called == 1) test_okay = 0; |