]>
Commit | Line | Data |
---|---|---|
6a8d3f1c OZ |
1 | /* |
2 | * BIRD -- I/O and event loop | |
3 | * | |
4 | * Can be freely distributed and used under the terms of the GNU GPL. | |
5 | */ | |
bf139664 | 6 | |
6a8d3f1c OZ |
7 | #ifndef _BIRD_BFD_IO_H_ |
8 | #define _BIRD_BFD_IO_H_ | |
bf139664 | 9 | |
6a8d3f1c OZ |
10 | #include "nest/bird.h" |
11 | #include "lib/lists.h" | |
12 | #include "lib/resource.h" | |
13 | #include "lib/event.h" | |
14 | #include "lib/socket.h" | |
15 | // #include "lib/timer.h" | |
16 | ||
17 | ||
6a8d3f1c | 18 | typedef struct timer2 |
bf139664 OZ |
19 | { |
20 | resource r; | |
21 | void (*hook)(struct timer2 *); | |
22 | void *data; | |
23 | ||
6a8d3f1c OZ |
24 | btime expires; /* 0=inactive */ |
25 | uint randomize; /* Amount of randomization */ | |
26 | uint recurrent; /* Timer recurrence */ | |
bf139664 OZ |
27 | |
28 | int index; | |
6a8d3f1c | 29 | } timer2; |
bf139664 OZ |
30 | |
31 | ||
6a8d3f1c | 32 | btime current_time(void); |
bf139664 OZ |
33 | |
34 | void ev2_schedule(event *e); | |
35 | ||
36 | ||
bf139664 | 37 | timer2 *tm2_new(pool *p); |
6a8d3f1c OZ |
38 | void tm2_set(timer2 *t, btime when); |
39 | void tm2_start(timer2 *t, btime after); | |
bf139664 OZ |
40 | void tm2_stop(timer2 *t); |
41 | ||
6a8d3f1c OZ |
42 | static inline int |
43 | tm2_active(timer2 *t) | |
bf139664 | 44 | { |
6a8d3f1c | 45 | return t->expires != 0; |
bf139664 OZ |
46 | } |
47 | ||
6a8d3f1c OZ |
48 | static inline btime |
49 | tm2_remains(timer2 *t) | |
bf139664 | 50 | { |
6a8d3f1c OZ |
51 | btime now = current_time(); |
52 | return (t->expires > now) ? (t->expires - now) : 0; | |
bf139664 OZ |
53 | } |
54 | ||
55 | static inline timer2 * | |
6a8d3f1c | 56 | tm2_new_init(pool *p, void (*hook)(struct timer2 *), void *data, uint rec, uint rand) |
bf139664 OZ |
57 | { |
58 | timer2 *t = tm2_new(p); | |
59 | t->hook = hook; | |
60 | t->data = data; | |
61 | t->recurrent = rec; | |
62 | t->randomize = rand; | |
63 | return t; | |
64 | } | |
65 | ||
1ec52253 OZ |
66 | static inline void |
67 | tm2_set_max(timer2 *t, btime when) | |
68 | { | |
69 | if (when > t->expires) | |
70 | tm2_set(t, when); | |
71 | } | |
72 | ||
6a8d3f1c OZ |
73 | /* |
74 | static inline void | |
75 | tm2_start_max(timer2 *t, btime after) | |
76 | { | |
77 | btime rem = tm2_remains(t); | |
41f8bf57 | 78 | tm2_start(t, MAX_(rem, after)); |
6a8d3f1c OZ |
79 | } |
80 | */ | |
bf139664 OZ |
81 | |
82 | ||
83 | void sk_start(sock *s); | |
84 | void sk_stop(sock *s); | |
85 | ||
86 | ||
87 | ||
1ec52253 | 88 | struct birdloop *birdloop_new(void); |
0e175f9f OZ |
89 | void birdloop_start(struct birdloop *loop); |
90 | void birdloop_stop(struct birdloop *loop); | |
1ec52253 OZ |
91 | void birdloop_free(struct birdloop *loop); |
92 | ||
bf139664 OZ |
93 | void birdloop_enter(struct birdloop *loop); |
94 | void birdloop_leave(struct birdloop *loop); | |
6a8d3f1c OZ |
95 | void birdloop_mask_wakeups(struct birdloop *loop); |
96 | void birdloop_unmask_wakeups(struct birdloop *loop); | |
97 | ||
bf139664 | 98 | |
6a8d3f1c | 99 | #endif /* _BIRD_BFD_IO_H_ */ |