1 /* Licensed under LGPLv2.1+ - see LICENSE file for details */
7 * struct io_plan - a plan of what I/O to do.
8 * @pollflag: POLLIN or POLLOUT.
9 * @io: function to call when fd is available for @pollflag.
10 * @next: function to call after @io returns true.
11 * @next_arg: argument to @next.
12 * @u1: scratch area for I/O.
13 * @u2: scratch area for I/O.
15 * When the fd is POLLIN or POLLOUT (according to @pollflag), @io is
16 * called. If it returns -1, io_close() becomed the new plan (and errno
17 * is saved). If it returns 1, @next is called, otherwise @io is
18 * called again when @pollflag is available.
20 * You can use this to write your own io_plan functions.
24 /* Only NULL if idle. */
25 int (*io)(int fd, struct io_plan *plan);
26 /* Only NULL if closing. */
27 struct io_plan (*next)(struct io_conn *, void *arg);
35 char c[sizeof(size_t)];
42 char c[sizeof(size_t)];
48 * io_debug_conn - routine to select connection(s) to debug.
50 * If this is set, the routine should return true if the connection is a
51 * debugging candidate. If so, the callchain for I/O operations on this
52 * connection will be linear, for easier use of a debugger.
54 * You will also see calls to any callbacks which wake the connection
55 * which is being debugged.
58 * static bool debug_all(struct io_conn *conn)
63 * io_debug_conn = debug_all;
65 extern bool (*io_debug_conn)(struct io_conn *conn);
68 * io_debug - if we're debugging the current connection, call immediately.
70 * This determines if we are debugging the current connection: if so,
71 * it immediately applies the plan and calls back into io_loop() to
72 * create a linear call chain.
75 * #define io_idle() io_debug(io_idle_())
76 * struct io_plan io_idle_(void);
78 struct io_plan io_debug(struct io_plan plan);
81 * io_debug_io - return from function which actually does I/O.
83 * This determines if we are debugging the current connection: if so,
84 * it immediately sets the next function and calls into io_loop() to
85 * create a linear call chain.
89 * static int do_write(int fd, struct io_plan *plan)
91 * ssize_t ret = write(fd, plan->u.write.buf, plan->u.write.len);
93 * return io_debug_io(-1);
95 * plan->u.write.buf += ret;
96 * plan->u.write.len -= ret;
97 * return io_debug_io(plan->u.write.len == 0);
100 int io_debug_io(int ret);
103 * io_plan_no_debug - mark the next plan not to be called immediately.
105 * Most routines which take a plan are about to apply it to the current
106 * connection. We (ab)use this pattern for debugging: as soon as such a
107 * plan is created it is called, to create a linear call chain.
109 * Some routines, like io_break(), io_duplex() and io_wake() take an
110 * io_plan, but they must not be applied immediately to the current
111 * connection, so we call this first.
114 * #define io_break(ret, plan) (io_plan_no_debug(), io_break_((ret), (plan)))
115 * struct io_plan io_break_(void *ret, struct io_plan plan);
117 #define io_plan_no_debug() ((io_plan_nodebug = true))
119 extern bool io_plan_nodebug;
121 static inline struct io_plan io_debug(struct io_plan plan)
125 static inline int io_debug_io(int ret)
129 #define io_plan_no_debug() (void)0
132 #endif /* CCAN_IO_PLAN_H */