From 09b4857c756ec320188f099d51697a708245e311 Mon Sep 17 00:00:00 2001 From: file Date: Wed, 17 Jan 2007 19:47:21 +0000 Subject: Add timeout capability similar to patlooptest to pattest. (issue #8837 reported by opticron) git-svn-id: http://svn.digium.com/svn/zaptel/trunk@1838 5390a7c7-147a-4af0-8ec9-7488f05a26cb --- pattest.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'pattest.c') diff --git a/pattest.c b/pattest.c index d7b6fca..1923614 100644 --- a/pattest.c +++ b/pattest.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "bittest.h" #ifdef STANDALONE_ZAPATA @@ -38,8 +39,10 @@ int main(int argc, char *argv[]) int setup=0; int errors=0; int bytes=0; + time_t start_time = 0; + int timeout = 0; if (argc < 2) { - fprintf(stderr, "Usage: markhdlctest \n"); + fprintf(stderr, "Usage: %s [optional timeout]\n",argv[0]); exit(1); } fd = open(argv[1], O_RDWR, 0600); @@ -56,6 +59,11 @@ int main(int argc, char *argv[]) exit(1); } ioctl(fd, ZT_GETEVENT); + if (argc == 3) { + timeout = atoi(argv[2]); + start_time = time(NULL); + printf("Using Timeout of %d Seconds\n",timeout); + } for(;;) { res = bs; res = read(fd, outbuf, res); @@ -99,6 +107,10 @@ int main(int argc, char *argv[]) #if 0 printf("(%d) Wrote %d bytes\n", packets++, res); #endif + if (timeout && (time(NULL) - start_time) > timeout) { + printf("Timeout achieved Ending Program\n"); + return errors; + } } } -- cgit v1.2.3