]> git.ozlabs.org Git - ccan/blob - ccan/io/backend.h
cpuid: fix example compilation
[ccan] / ccan / io / backend.h
1 /* Licensed under LGPLv2.1+ - see LICENSE file for details */
2 #ifndef CCAN_IO_BACKEND_H
3 #define CCAN_IO_BACKEND_H
4 #include <stdbool.h>
5 #include <ccan/timer/timer.h>
6
7 struct io_alloc {
8         void *(*alloc)(size_t size);
9         void *(*realloc)(void *ptr, size_t size);
10         void (*free)(void *ptr);
11 };
12 extern struct io_alloc io_alloc;
13
14 struct fd {
15         int fd;
16         bool listener;
17         size_t backend_info;
18 };
19
20 /* Listeners create connections. */
21 struct io_listener {
22         struct fd fd;
23
24         /* These are for connections we create. */
25         void (*init)(int fd, void *arg);
26         void *arg;
27 };
28
29 struct io_timeout {
30         struct timer timer;
31         struct io_conn *conn;
32
33         struct io_plan (*next)(struct io_conn *, void *arg);
34         void *next_arg;
35 };
36
37 /* One connection per client. */
38 struct io_conn {
39         struct fd fd;
40
41         void (*finish)(struct io_conn *, void *arg);
42         void *finish_arg;
43
44         struct io_conn *duplex;
45         struct io_timeout *timeout;
46
47         struct io_plan plan;
48 };
49
50 static inline bool timeout_active(const struct io_conn *conn)
51 {
52         return conn->timeout && conn->timeout->conn;
53 }
54
55 extern void *io_loop_return;
56
57 #ifdef DEBUG
58 extern struct io_conn *current;
59 static inline void set_current(struct io_conn *conn)
60 {
61         current = conn;
62 }
63 static inline bool doing_debug_on(struct io_conn *conn)
64 {
65         return io_debug_conn && io_debug_conn(conn);
66 }
67 static inline bool doing_debug(void)
68 {
69         return io_debug_conn;
70 }
71 #else
72 static inline void set_current(struct io_conn *conn)
73 {
74 }
75 static inline bool doing_debug_on(struct io_conn *conn)
76 {
77         return false;
78 }
79 static inline bool doing_debug(void)
80 {
81         return false;
82 }
83 #endif
84
85 bool add_listener(struct io_listener *l);
86 bool add_conn(struct io_conn *c);
87 bool add_duplex(struct io_conn *c);
88 void del_listener(struct io_listener *l);
89 void backend_plan_changed(struct io_conn *conn);
90 void backend_add_timeout(struct io_conn *conn, struct timespec ts);
91 void backend_del_timeout(struct io_conn *conn);
92 void backend_del_conn(struct io_conn *conn);
93
94 void io_ready(struct io_conn *conn);
95 void *do_io_loop(struct io_conn **ready);
96 #endif /* CCAN_IO_BACKEND_H */