[zaptel-commits] file: trunk r1838 - /trunk/pattest.c

zaptel-commits at lists.digium.com zaptel-commits at lists.digium.com
Wed Jan 17 12:47:22 MST 2007


Author: file
Date: Wed Jan 17 13:47:21 2007
New Revision: 1838

URL: http://svn.digium.com/view/zaptel?view=rev&rev=1838
Log:
Add timeout capability similar to patlooptest to pattest. (issue #8837 reported by opticron)

Modified:
    trunk/pattest.c

Modified: trunk/pattest.c
URL: http://svn.digium.com/view/zaptel/trunk/pattest.c?view=diff&rev=1838&r1=1837&r2=1838
==============================================================================
--- trunk/pattest.c (original)
+++ trunk/pattest.c Wed Jan 17 13:47:21 2007
@@ -8,6 +8,7 @@
 #include <sys/ioctl.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <time.h>
 #include "bittest.h"
 
 #ifdef STANDALONE_ZAPATA
@@ -38,8 +39,10 @@
 	int setup=0;
 	int errors=0;
 	int bytes=0;
+	time_t start_time = 0;
+	int timeout = 0;
 	if (argc < 2) {
-		fprintf(stderr, "Usage: markhdlctest <tor device>\n");
+		fprintf(stderr, "Usage: %s <zap device> [optional timeout]\n",argv[0]);
 		exit(1);
 	}
 	fd = open(argv[1], O_RDWR, 0600);
@@ -56,6 +59,11 @@
 		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 @@
 #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;
+		}
 	}
 	
 }



More information about the zaptel-commits mailing list