1 /* Licensed under LGPLv2.1+ - see LICENSE file for details */
7 * union io_plan_union - type for struct io_plan read/write fns.
14 char c[sizeof(size_t)];
18 * struct io_plan_arg - scratch space for struct io_plan read/write fns.
21 union io_plan_union u1, u2;
30 * io_plan_arg - get a conn's io_plan_arg for a given direction.
31 * @conn: the connection.
32 * @dir: IO_IN or IO_OUT.
34 * This is how an io helper gets scratch space to store into; you must call
35 * io_set_plan() when you've initialized it.
38 * #include <ccan/io/io_plan.h>
40 * // Simple helper to read a single char.
41 * static int do_readchar(int fd, struct io_plan_arg *arg)
43 * return read(fd, arg->u1.cp, 1) <= 0 ? -1 : 1;
46 * static struct io_plan *io_read_char_(struct io_conn *conn, char *in,
47 * struct io_plan *(*next)(struct io_conn*,void*),
50 * struct io_plan_arg *arg = io_plan_arg(conn, IO_IN);
52 * // Store information we need in the plan unions u1 and u2.
55 * return io_set_plan(conn, IO_IN, do_readchar, next, next_arg);
58 struct io_plan_arg *io_plan_arg(struct io_conn *conn, enum io_direction dir);
61 * io_set_plan - set a conn's io_plan.
62 * @conn: the connection.
63 * @dir: IO_IN or IO_OUT.
64 * @io: the IO function to call when the fd is ready.
65 * @next: the next callback when @io returns 1.
66 * @next_arg: the argument to @next.
68 * If @conn has debug set, the io function will be called immediately,
69 * so it's important that this be the last thing in your function!
74 struct io_plan *io_set_plan(struct io_conn *conn, enum io_direction dir,
75 int (*io)(int fd, struct io_plan_arg *arg),
76 struct io_plan *(*next)(struct io_conn *, void *),
78 #endif /* CCAN_IO_PLAN_H */