From 05a2c22fee8821e7d36837e1b3cba3b105dd5dfc Mon Sep 17 00:00:00 2001 From: Harlan Stenn Date: Sun, 13 Feb 2011 01:30:37 -0500 Subject: [PATCH] Make test-eof fail with a timeout if we never get an eof. Previously, it would just wait forever. --- test/test-eof.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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();