]> git.ozlabs.org Git - ccan/blob - ccan/io/backend.h
9f8c546c06a6a28135f8ffe2d2176e009e1e6b34
[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 <poll.h>
6 #include "io_plan.h"
7
8 struct fd {
9         int fd;
10         bool listener;
11         size_t backend_info;
12 };
13
14 /* Listeners create connections. */
15 struct io_listener {
16         struct fd fd;
17
18         const tal_t *ctx;
19
20         /* These are for connections we create. */
21         struct io_plan *(*init)(struct io_conn *conn, void *arg);
22         void *arg;
23 };
24
25 /* One connection per client. */
26 struct io_conn {
27         struct fd fd;
28         bool debug;
29         /* For duplex to save. */
30         bool debug_saved;
31
32         /* always or closing list. */
33         struct io_conn *list;
34
35         void (*finish)(struct io_conn *, void *arg);
36         void *finish_arg;
37
38         struct io_plan plan[2];
39 };
40
41 extern void *io_loop_return;
42
43 bool add_listener(struct io_listener *l);
44 bool add_conn(struct io_conn *c);
45 bool add_duplex(struct io_conn *c);
46 void del_listener(struct io_listener *l);
47 void backend_new_closing(struct io_conn *conn);
48 void backend_new_always(struct io_conn *conn);
49 void backend_new_plan(struct io_conn *conn);
50 void remove_from_always(struct io_conn *conn);
51 void backend_plan_done(struct io_conn *conn);
52
53 void backend_wake(const void *wait);
54 void backend_del_conn(struct io_conn *conn);
55
56 void io_ready(struct io_conn *conn, int pollflags);
57 void io_do_always(struct io_conn *conn);
58 void io_do_wakeup(struct io_conn *conn, struct io_plan *plan);
59 void *do_io_loop(struct io_conn **ready);
60 #endif /* CCAN_IO_BACKEND_H */