xref: /iperf/src/t_timer.c (revision ba7b91d2)
1 /*
2  * Copyright (c) 2009-2011, The Regents of the University of California,
3  * through Lawrence Berkeley National Laboratory (subject to receipt of any
4  * required approvals from the U.S. Dept. of Energy).  All rights reserved.
5  *
6  * This code is distributed under a BSD style license, see the LICENSE file
7  * for complete information.
8  */
9 
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <unistd.h>
13 #include <sys/time.h>
14 
15 #include "timer.h"
16 
17 
18 static int flag;
19 
20 
21 static void
22 timer_proc( TimerClientData client_data, struct timeval* nowP )
23 {
24     flag = 1;
25 }
26 
27 
28 int
29 main(int argc, char **argv)
30 {
31     Timer *tp;
32 
33     flag = 0;
34     tp = tmr_create((struct timeval*) 0, timer_proc, JunkClientData, 3000000, 0);
35 
36     sleep(2);
37 
38     tmr_run((struct timeval*) 0);
39     if (flag)
40     {
41 	printf("timer should not have expired\n");
42 	exit(-1);
43     }
44     sleep(1);
45 
46     tmr_run((struct timeval*) 0);
47     if (!flag)
48     {
49 	printf("timer should have expired\n");
50 	exit(-2);
51     }
52 
53     tmr_destroy();
54     exit(0);
55 }
56