Make test-eof fail with a timeout if we never get an eof.

Previously, it would just wait forever.
This commit is contained in:
Harlan Stenn 2011-02-13 01:30:37 -05:00 committed by Nick Mathewson
parent 4eb281c8a9
commit 05a2c22fee

View File

@ -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();