]> git.llucax.com Git - software/eventxx.git/blob - test/test-time.cpp
Minor documentation fixes.
[software/eventxx.git] / test / test-time.cpp
1 /*
2  * Compile with:
3  * c++ -I/usr/local/include -o time-test time-test.cpp -L/usr/local/lib -levent
4  *
5  * Wed 2006-12-27 - Modified by Leandro Lucarella <llucarella@integratech.com.ar>
6  *
7  *     Adapted to test the C++ inteface.
8  *
9  */
10
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <sys/time.h>
14 #include <fcntl.h>
15 #include <unistd.h>
16 #include <cstdlib>
17 #include <cstdio>
18 #include <cstring>
19 #include <cerrno>
20
21 #include <event>
22
23 int called = 0;
24
25 #define NEVENT  20000
26
27 event::ctimer* ev[NEVENT];
28 event::dispatcher d;
29
30 void
31 time_cb(int fd, short event, void *arg)
32 {
33         called++;
34
35         if (called < 10*NEVENT) {
36                 for (int i = 0; i < 10; i++) {
37                         event::time tv(0, random() % 50000L);
38                         int j = random() % NEVENT;
39                         if (tv.usec() % 2)
40                                 d.add(*ev[j], tv);
41                         else
42                                 d.del(*ev[j]);
43                 }
44         }
45 }
46
47 int
48 main (int argc, char **argv)
49 {
50         for (int i = 0; i < NEVENT; i++) {
51                 /* Initalize one event */
52                 ev[i] = new event::ctimer(time_cb, NULL);
53                 d.add(*ev[i], event::time(0, random() % 50000L));
54         }
55
56         d.dispatch();
57
58         return (called < NEVENT);
59 }
60