Blob


1 /*
2 * This is free and unencumbered software released into the public domain.
3 *
4 * Anyone is free to copy, modify, publish, use, compile, sell, or
5 * distribute this software, either in source code form or as a compiled
6 * binary, for any purpose, commercial or non-commercial, and by any
7 * means.
8 *
9 * In jurisdictions that recognize copyright laws, the author or authors
10 * of this software dedicate any and all copyright interest in the
11 * software to the public domain. We make this dedication for the benefit
12 * of the public at large and to the detriment of our heirs and
13 * successors. We intend this dedication to be an overt act of
14 * relinquishment in perpetuity of all present and future rights to this
15 * software under copyright law.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
26 #include "compat.h"
28 #include <assert.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <unistd.h>
33 #include <poll.h>
35 #include "ev.h"
37 int fired_a;
38 int fired_b;
39 int fired_c;
41 struct timeval tv_a = { 0, 250000 };
42 struct timeval tv_b = { 0, 300000 };
43 struct timeval tv_c = { 0, 350000 };
45 unsigned long tout_a;
46 unsigned long tout_b;
47 unsigned long tout_c;
49 static void
50 pipe_ev(int fd, int ev, void *data)
51 {
52 warn("shouldn't have happened!");
53 abort();
54 }
56 static void
57 timeout_cb(int fd, int ev, void *data)
58 {
59 int *d = data;
61 assert(fd == -1);
62 *d = 1;
63 }
65 static void
66 timeout_cancel_b(int fd, int ev, void *data)
67 {
68 timeout_cb(fd, ev, data);
69 ev_timer_cancel(tout_b);
70 }
72 static void
73 timeout_quit(int fd, int ev, void *data)
74 {
75 timeout_cb(fd, ev, data);
76 ev_break();
77 }
79 int
80 main(void)
81 {
82 int p[2];
84 alarm(2); /* safety net */
86 /* the ev subsystem needs at least a file descriptor */
87 if (pipe(p) == -1)
88 err(1, "pipe");
90 if (ev_init() == -1)
91 err(1, "ev_init");
93 if (ev_add(p[0], POLLIN, pipe_ev, NULL) == -1)
94 err(1, "ev_add");
96 if ((tout_c = ev_timer(&tv_c, timeout_quit, &fired_c)) == 0 ||
97 (tout_b = ev_timer(&tv_b, timeout_cb, &fired_b)) == 0 ||
98 (tout_a = ev_timer(&tv_a, timeout_cancel_b, &fired_a)) == 0)
99 err(1, "ev_timer");
101 ev_loop();
103 if (fired_a && !fired_b && fired_c)
104 return 0;
106 errx(1, "events fired not as expected: a:%d b:%d c:%d",
107 fired_a, fired_b, fired_c);