1 /* Licensed under LGPLv2.1+ - see LICENSE file for details */
2 #ifndef CCAN_IO_BACKEND_H
3 #define CCAN_IO_BACKEND_H
6 #include <ccan/list/list.h>
14 /* Listeners create connections. */
20 /* These are for connections we create. */
21 struct io_plan *(*init)(struct io_conn *conn, void *arg);
26 /* As before calling next function. */
28 /* Normal, but haven't started yet. */
29 IO_POLLING_NOTSTARTED,
31 /* Waiting for io_wake */
38 * struct io_plan - one half of I/O to do
39 * @status: the status of this plan.
40 * @dir: are we plan[0] or plan[1] inside io_conn?
41 * @io: function to call when fd becomes read/writable, returns 0 to be
42 * called again, 1 if it's finished, and -1 on error (fd will be closed)
43 * @next: the next function which is called if io returns 1.
44 * @next_arg: the argument to @next
45 * @u1, @u2: scratch space for @io.
48 enum io_plan_status status;
49 enum io_direction dir;
51 int (*io)(int fd, struct io_plan_arg *arg);
53 struct io_plan *(*next)(struct io_conn *, void *next_arg);
56 struct io_plan_arg arg;
59 /* One connection per client. */
63 void (*finish)(struct io_conn *, void *arg);
66 struct io_plan plan[2];
69 extern void *io_loop_return;
71 bool add_listener(struct io_listener *l);
72 bool add_conn(struct io_conn *c);
73 bool add_duplex(struct io_conn *c);
74 void del_listener(struct io_listener *l);
75 void cleanup_conn_without_close(struct io_conn *c);
76 bool backend_new_always(struct io_plan *plan);
77 void backend_new_plan(struct io_conn *conn);
78 void backend_plan_done(struct io_conn *conn);
80 void backend_wake(const void *wait);
82 void io_ready(struct io_conn *conn, int pollflags);
83 void io_do_always(struct io_plan *conn);
84 void io_do_wakeup(struct io_conn *conn, enum io_direction dir);
85 void *do_io_loop(struct io_conn **ready);
86 #endif /* CCAN_IO_BACKEND_H */