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);
25 /* These wait for something to input */
29 /* These wait for room to output */
33 NEXT, /* eg starting, woken from idle, return from io_break. */
36 PROCESSING /* We expect them to change this now. */
39 static inline enum io_state from_ioplan(struct io_plan *op)
41 return (enum io_state)(long)op;
44 struct io_state_read {
49 struct io_state_write {
54 struct io_state_readpart {
59 struct io_state_writepart {
68 struct io_plan *(*next)(struct io_conn *, void *arg);
72 /* One connection per client. */
76 struct io_plan *(*next)(struct io_conn *, void *arg);
79 void (*finish)(struct io_conn *, void *arg);
82 struct io_conn *duplex;
83 struct io_timeout *timeout;
85 int pollflag; /* 0, POLLIN or POLLOUT */
88 struct io_state_read read;
89 struct io_state_write write;
90 struct io_state_readpart readpart;
91 struct io_state_writepart writepart;
95 static inline bool timeout_active(const struct io_conn *conn)
97 return conn->timeout && conn->timeout->conn;
100 extern void *io_loop_return;
102 bool add_listener(struct io_listener *l);
103 bool add_conn(struct io_conn *c);
104 bool add_duplex(struct io_conn *c);
105 void del_listener(struct io_listener *l);
106 void backend_set_state(struct io_conn *conn, struct io_plan *op);
107 void backend_add_timeout(struct io_conn *conn, struct timespec ts);
108 void backend_del_timeout(struct io_conn *conn);
110 struct io_plan *do_ready(struct io_conn *conn);
111 #endif /* CCAN_IO_BACKEND_H */