]> git.ozlabs.org Git - ccan/blob - ccan/io/io_plan.h
ccan/io: rewrite.
[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 /**
31  * struct io_plan - one half of I/O to do
32  * @status: the status of this plan.
33  * @io: function to call when fd becomes read/writable, returns 0 to be
34  *      called again, 1 if it's finished, and -1 on error (fd will be closed)
35  * @next: the next function which is called if io returns 1.
36  * @next_arg: the argument to @next
37  * @u1, @u2: scratch space for @io.
38  */
39 struct io_plan {
40         enum io_plan_status status;
41
42         int (*io)(int fd, struct io_plan *plan);
43
44         struct io_plan *(*next)(struct io_conn *, void *arg);
45         void *next_arg;
46
47         union io_plan_arg u1, u2;
48 };
49
50 /* Helper to get a conn's io_plan. */
51 struct io_plan *io_get_plan(struct io_conn *conn, enum io_direction dir);
52
53 #endif /* CCAN_IO_PLAN_H */