]> git.ozlabs.org Git - ccan/blob - ccan/io/backend.h
ccan/io: pass struct io_plan explicitly.
[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 fd {
8         int fd;
9         bool listener;
10         size_t backend_info;
11 };
12
13 /* Listeners create connections. */
14 struct io_listener {
15         struct fd fd;
16
17         /* These are for connections we create. */
18         struct io_plan (*next)(struct io_conn *, void *arg);
19         void (*finish)(struct io_conn *, void *arg);
20         void *conn_arg;
21 };
22
23 struct io_timeout {
24         struct timer timer;
25         struct io_conn *conn;
26
27         struct io_plan (*next)(struct io_conn *, void *arg);
28         void *next_arg;
29 };
30
31 /* One connection per client. */
32 struct io_conn {
33         struct fd fd;
34
35         void (*finish)(struct io_conn *, void *arg);
36         void *finish_arg;
37
38         struct io_conn *duplex;
39         struct io_timeout *timeout;
40
41         struct io_plan plan;
42 };
43
44 static inline bool timeout_active(const struct io_conn *conn)
45 {
46         return conn->timeout && conn->timeout->conn;
47 }
48
49 extern void *io_loop_return;
50
51 bool add_listener(struct io_listener *l);
52 bool add_conn(struct io_conn *c);
53 bool add_duplex(struct io_conn *c);
54 void del_listener(struct io_listener *l);
55 void backend_wakeup(struct io_conn *conn);
56 void backend_add_timeout(struct io_conn *conn, struct timespec ts);
57 void backend_del_timeout(struct io_conn *conn);
58
59 struct io_plan do_ready(struct io_conn *conn);
60 #endif /* CCAN_IO_BACKEND_H */