]> git.ipfire.org Git - thirdparty/bird.git/blame - proto/bfd/io.h
Finishes add-path.
[thirdparty/bird.git] / proto / bfd / io.h
CommitLineData
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 18typedef 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 32btime current_time(void);
bf139664
OZ
33
34void ev2_schedule(event *e);
35
36
bf139664 37timer2 *tm2_new(pool *p);
6a8d3f1c
OZ
38void tm2_set(timer2 *t, btime when);
39void tm2_start(timer2 *t, btime after);
bf139664
OZ
40void tm2_stop(timer2 *t);
41
6a8d3f1c
OZ
42static inline int
43tm2_active(timer2 *t)
bf139664 44{
6a8d3f1c 45 return t->expires != 0;
bf139664
OZ
46}
47
6a8d3f1c
OZ
48static inline btime
49tm2_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
55static inline timer2 *
6a8d3f1c 56tm2_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
66static inline void
67tm2_set_max(timer2 *t, btime when)
68{
69 if (when > t->expires)
70 tm2_set(t, when);
71}
72
6a8d3f1c
OZ
73/*
74static inline void
75tm2_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
83void sk_start(sock *s);
84void sk_stop(sock *s);
85
86
87
1ec52253 88struct birdloop *birdloop_new(void);
0e175f9f
OZ
89void birdloop_start(struct birdloop *loop);
90void birdloop_stop(struct birdloop *loop);
1ec52253
OZ
91void birdloop_free(struct birdloop *loop);
92
bf139664
OZ
93void birdloop_enter(struct birdloop *loop);
94void birdloop_leave(struct birdloop *loop);
6a8d3f1c
OZ
95void birdloop_mask_wakeups(struct birdloop *loop);
96void birdloop_unmask_wakeups(struct birdloop *loop);
97
bf139664 98
6a8d3f1c 99#endif /* _BIRD_BFD_IO_H_ */