X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fio%2Fio_plan.h;h=61d762454463b0f12868ff5a74fcdccbaa265f32;hp=86be1d70d080721c1d490ae9c0e680e242470918;hb=5a7e32bdb9b9c2273ef4cce8b35e23f177c504df;hpb=9e02685a6216720d37848a332187e3745b7f981e diff --git a/ccan/io/io_plan.h b/ccan/io/io_plan.h index 86be1d70..61d76245 100644 --- a/ccan/io/io_plan.h +++ b/ccan/io/io_plan.h @@ -9,7 +9,8 @@ struct io_conn; * @io: function to call when fd is available for @pollflag. * @next: function to call after @io returns true. * @next_arg: argument to @next. - * @u: scratch area for I/O. + * @u1: scratch area for I/O. + * @u2: scratch area for I/O. * * When the fd is POLLIN or POLLOUT (according to @pollflag), @io is * called. If it returns -1, io_close() becomed the new plan (and errno @@ -27,38 +28,19 @@ struct io_plan { void *next_arg; union { - struct { - char *buf; - size_t len; - } read; - struct { - const char *buf; - size_t len; - } write; - struct { - char *buf; - size_t *lenp; - } readpart; - struct { - const char *buf; - size_t *lenp; - } writepart; - struct { - int saved_errno; - } close; - struct { - void *p; - size_t len; - } ptr_len; - struct { - void *p1; - void *p2; - } ptr_ptr; - struct { - size_t len1; - size_t len2; - } len_len; - } u; + char *cp; + void *vp; + const void *const_vp; + size_t s; + char c[sizeof(size_t)]; + } u1; + union { + char *p; + void *vp; + const void *const_vp; + size_t s; + char c[sizeof(size_t)]; + } u2; }; #ifdef DEBUG @@ -68,6 +50,17 @@ struct io_plan { * If this is set, the routine should return true if the connection is a * debugging candidate. If so, the callchain for I/O operations on this * connection will be linear, for easier use of a debugger. + * + * You will also see calls to any callbacks which wake the connection + * which is being debugged. + * + * Example: + * static bool debug_all(struct io_conn *conn) + * { + * return true(); + * } + * ... + * io_debug_conn = debug_all; */ extern bool (*io_debug_conn)(struct io_conn *conn); @@ -77,9 +70,35 @@ extern bool (*io_debug_conn)(struct io_conn *conn); * This determines if we are debugging the current connection: if so, * it immediately applies the plan and calls back into io_loop() to * create a linear call chain. + * + * Example: + * #define io_idle() io_debug(io_idle_()) + * struct io_plan io_idle_(void); */ struct io_plan io_debug(struct io_plan plan); +/** + * io_debug_io - return from function which actually does I/O. + * + * This determines if we are debugging the current connection: if so, + * it immediately sets the next function and calls into io_loop() to + * create a linear call chain. + * + * Example: + * + * static int do_write(int fd, struct io_plan *plan) + * { + * ssize_t ret = write(fd, plan->u.write.buf, plan->u.write.len); + * if (ret < 0) + * return io_debug_io(-1); + * + * plan->u.write.buf += ret; + * plan->u.write.len -= ret; + * return io_debug_io(plan->u.write.len == 0); + * } + */ +int io_debug_io(int ret); + /** * io_plan_no_debug - mark the next plan not to be called immediately. * @@ -90,6 +109,10 @@ struct io_plan io_debug(struct io_plan plan); * Some routines, like io_break(), io_duplex() and io_wake() take an * io_plan, but they must not be applied immediately to the current * connection, so we call this first. + * + * Example: + * #define io_break(ret, plan) (io_plan_no_debug(), io_break_((ret), (plan))) + * struct io_plan io_break_(void *ret, struct io_plan plan); */ #define io_plan_no_debug() ((io_plan_nodebug = true)) @@ -99,6 +122,10 @@ static inline struct io_plan io_debug(struct io_plan plan) { return plan; } +static inline int io_debug_io(int ret) +{ + return ret; +} #define io_plan_no_debug() (void)0 #endif