xref: /iperf/src/t_timer.c (revision 4874c4a8)
1 /*
2  * iperf, Copyright (c) 2014, The Regents of the University of
3  * California, through Lawrence Berkeley National Laboratory (subject
4  * to receipt of any required approvals from the U.S. Dept. of
5  * Energy).  All rights reserved.
6  *
7  * If you have questions about your rights to use or distribute this
8  * software, please contact Berkeley Lab's Technology Transfer
9  * Department at [email protected].
10  *
11  * NOTICE.  This software is owned by the U.S. Department of Energy.
12  * As such, the U.S. Government has been granted for itself and others
13  * acting on its behalf a paid-up, nonexclusive, irrevocable,
14  * worldwide license in the Software to reproduce, prepare derivative
15  * works, and perform publicly and display publicly.  Beginning five
16  * (5) years after the date permission to assert copyright is obtained
17  * from the U.S. Department of Energy, and subject to any subsequent
18  * five (5) year renewals, the U.S. Government is granted for itself
19  * and others acting on its behalf a paid-up, nonexclusive,
20  * irrevocable, worldwide license in the Software to reproduce,
21  * prepare derivative works, distribute copies to the public, perform
22  * publicly and display publicly, and to permit others to do so.
23  *
24  * This code is distributed under a BSD style license, see the LICENSE
25  * file for complete information.
26  */
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <sys/time.h>
31 
32 #include "timer.h"
33 
34 
35 static int flag;
36 
37 
38 static void
39 timer_proc( TimerClientData client_data, struct timeval* nowP )
40 {
41     flag = 1;
42 }
43 
44 
45 int
46 main(int argc, char **argv)
47 {
48     Timer *tp;
49 
50     flag = 0;
51     tp = tmr_create((struct timeval*) 0, timer_proc, JunkClientData, 3000000, 0);
52     if (!tp)
53     {
54 	printf("failed to create timer\n");
55 	exit(-1);
56     }
57 
58     sleep(2);
59 
60     tmr_run((struct timeval*) 0);
61     if (flag)
62     {
63 	printf("timer should not have expired\n");
64 	exit(-1);
65     }
66     sleep(1);
67 
68     tmr_run((struct timeval*) 0);
69     if (!flag)
70     {
71 	printf("timer should have expired\n");
72 	exit(-2);
73     }
74 
75     tmr_destroy();
76     exit(0);
77 }
78