]> git.ozlabs.org Git - ccan/blob - ccan/io/io_plan.h
21a1921734f41e83d2ed836e157e4849496fb8ad
[ccan] / ccan / io / io_plan.h
1 /* Licensed under LGPLv2.1+ - see LICENSE file for details */
2 #ifndef CCAN_IO_PLAN_H
3 #define CCAN_IO_PLAN_H
4 struct io_conn;
5
6 /**
7  * union io_plan_arg - scratch space for struct io_plan read/write fns.
8  */
9 union io_plan_arg {
10         char *cp;
11         void *vp;
12         const void *const_vp;
13         size_t s;
14         char c[sizeof(size_t)];
15 };
16
17 enum io_plan_status {
18         /* As before calling next function. */
19         IO_UNSET,
20         /* Normal. */
21         IO_POLLING,
22         /* Waiting for io_wake */
23         IO_WAITING,
24         /* Always do this. */
25         IO_ALWAYS,
26         /* Closing (both plans will be the same). */
27         IO_CLOSING
28 };
29
30 enum io_direction {
31         IO_IN,
32         IO_OUT
33 };
34
35 /**
36  * struct io_plan - one half of I/O to do
37  * @status: the status of this plan.
38  * @io: function to call when fd becomes read/writable, returns 0 to be
39  *      called again, 1 if it's finished, and -1 on error (fd will be closed)
40  * @next: the next function which is called if io returns 1.
41  * @next_arg: the argument to @next
42  * @u1, @u2: scratch space for @io.
43  */
44 struct io_plan {
45         enum io_plan_status status;
46
47         int (*io)(int fd, struct io_plan *plan);
48
49         struct io_plan *(*next)(struct io_conn *, void *arg);
50         void *next_arg;
51
52         union io_plan_arg u1, u2;
53 };
54
55 /* Helper to get a conn's io_plan. */
56 struct io_plan *io_get_plan(struct io_conn *conn, enum io_direction dir);
57
58 #endif /* CCAN_IO_PLAN_H */