X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fio%2Fio_plan.h;h=1d503133b6ddb24f4f50cb2e4d12c4fb3e9732d3;hb=ace6131ed7d12a48fc6f019a0d69e94f30c5cd3e;hp=3bc2770ffb4abf8e997ad7aa6ea2e62ce6c54e86;hpb=318f717e34e4735e5397bee24dbbee69205be82b;p=ccan diff --git a/ccan/io/io_plan.h b/ccan/io/io_plan.h index 3bc2770f..1d503133 100644 --- a/ccan/io/io_plan.h +++ b/ccan/io/io_plan.h @@ -4,9 +4,9 @@ struct io_conn; /** - * union io_plan_arg - scratch space for struct io_plan read/write fns. + * union io_plan_union - type for struct io_plan read/write fns. */ -union io_plan_arg { +union io_plan_union { char *cp; void *vp; const void *const_vp; @@ -14,17 +14,11 @@ union io_plan_arg { char c[sizeof(size_t)]; }; -enum io_plan_status { - /* As before calling next function. */ - IO_UNSET, - /* Normal. */ - IO_POLLING, - /* Waiting for io_wake */ - IO_WAITING, - /* Always do this. */ - IO_ALWAYS, - /* Closing (both plans will be the same). */ - IO_CLOSING +/** + * struct io_plan_arg - scratch space for struct io_plan read/write fns. + */ +struct io_plan_arg { + union io_plan_union u1, u2; }; enum io_direction { @@ -33,58 +27,40 @@ enum io_direction { }; /** - * struct io_plan - one half of I/O to do - * @status: the status of this plan. - * @io: function to call when fd becomes read/writable, returns 0 to be - * called again, 1 if it's finished, and -1 on error (fd will be closed) - * @next: the next function which is called if io returns 1. - * @next_arg: the argument to @next - * @u1, @u2: scratch space for @io. - */ -struct io_plan { - enum io_plan_status status; - - int (*io)(int fd, struct io_plan *plan); - - struct io_plan *(*next)(struct io_conn *, void *arg); - void *next_arg; - - union io_plan_arg u1, u2; -}; - -/** - * io_get_plan - get a conn's io_plan for a given direction. + * io_plan_arg - get a conn's io_plan_arg for a given direction. * @conn: the connection. * @dir: IO_IN or IO_OUT. * - * This is how an io helper gets a plan to store into; you must call - * io_done_plan() when you've initialized it. + * This is how an io helper gets scratch space to store into; you must call + * io_set_plan() when you've initialized it. * * Example: + * #include + * * // Simple helper to read a single char. - * static int do_readchar(int fd, struct io_plan *plan) + * static int do_readchar(int fd, struct io_plan_arg *arg) * { - * return read(fd, plan->u1.cp, 1) <= 0 ? -1 : 1; + * return read(fd, arg->u1.cp, 1) <= 0 ? -1 : 1; * } * - * struct io_plan *io_read_char_(struct io_conn *conn, char *in, + * static struct io_plan *io_read_char_(struct io_conn *conn, char *in, * struct io_plan *(*next)(struct io_conn*,void*), - * void *arg) + * void *next_arg) * { - * struct io_plan *plan = io_get_plan(conn, IO_IN); + * struct io_plan_arg *arg = io_plan_arg(conn, IO_IN); * * // Store information we need in the plan unions u1 and u2. - * plan->u1.cp = in; + * arg->u1.cp = in; * - * return io_set_plan(conn, plan, do_readchar, next, arg); + * return io_set_plan(conn, IO_IN, do_readchar, next, next_arg); * } */ -struct io_plan *io_get_plan(struct io_conn *conn, enum io_direction dir); +struct io_plan_arg *io_plan_arg(struct io_conn *conn, enum io_direction dir); /** * io_set_plan - set a conn's io_plan. * @conn: the connection. - * @plan: the plan + * @dir: IO_IN or IO_OUT. * @io: the IO function to call when the fd is ready. * @next: the next callback when @io returns 1. * @next_arg: the argument to @next. @@ -93,10 +69,10 @@ struct io_plan *io_get_plan(struct io_conn *conn, enum io_direction dir); * so it's important that this be the last thing in your function! * * See also: - * io_get_plan() + * io_get_plan_arg() */ -struct io_plan *io_set_plan(struct io_conn *conn, struct io_plan *plan, - int (*io)(int fd, struct io_plan *plan), +struct io_plan *io_set_plan(struct io_conn *conn, enum io_direction dir, + int (*io)(int fd, struct io_plan_arg *arg), struct io_plan *(*next)(struct io_conn *, void *), void *next_arg); #endif /* CCAN_IO_PLAN_H */