1 /* Licensed under LGPLv2.1+ - see LICENSE file for details */
2 #ifndef CCAN_IO_BACKEND_H
3 #define CCAN_IO_BACKEND_H
5 #include <ccan/timer/timer.h>
14 /* Listeners create connections. */
18 /* These are for connections we create. */
19 struct io_plan *(*next)(struct io_conn *, void *arg);
20 void (*finish)(struct io_conn *, void *arg);
32 NEXT, /* eg starting, woken from idle, return from io_break. */
35 PROCESSING /* We expect them to change this now. */
38 static inline enum io_state from_ioplan(struct io_plan *op)
40 return (enum io_state)(long)op;
43 struct io_state_read {
48 struct io_state_write {
53 struct io_state_readpart {
58 struct io_state_writepart {
67 struct io_plan *(*next)(struct io_conn *, void *arg);
71 /* One connection per client. */
75 struct io_plan *(*next)(struct io_conn *, void *arg);
78 void (*finish)(struct io_conn *, void *arg);
81 struct io_conn *duplex;
82 struct io_timeout *timeout;
84 enum io_result (*io)(struct io_conn *conn);
86 int pollflag; /* 0, POLLIN or POLLOUT */
89 struct io_state_read read;
90 struct io_state_write write;
91 struct io_state_readpart readpart;
92 struct io_state_writepart writepart;
96 static inline bool timeout_active(const struct io_conn *conn)
98 return conn->timeout && conn->timeout->conn;
101 extern void *io_loop_return;
103 bool add_listener(struct io_listener *l);
104 bool add_conn(struct io_conn *c);
105 bool add_duplex(struct io_conn *c);
106 void del_listener(struct io_listener *l);
107 void backend_set_state(struct io_conn *conn, struct io_plan *op);
108 void backend_add_timeout(struct io_conn *conn, struct timespec ts);
109 void backend_del_timeout(struct io_conn *conn);
111 struct io_plan *do_ready(struct io_conn *conn);
112 #endif /* CCAN_IO_BACKEND_H */