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>
8 void *(*alloc)(size_t size);
9 void *(*realloc)(void *ptr, size_t size);
10 void (*free)(void *ptr);
12 extern struct io_alloc io_alloc;
20 /* Listeners create connections. */
24 /* These are for connections we create. */
25 void (*init)(int fd, void *arg);
33 struct io_plan (*next)(struct io_conn *, void *arg);
37 /* One connection per client. */
41 void (*finish)(struct io_conn *, void *arg);
44 struct io_conn *duplex;
45 struct io_timeout *timeout;
50 static inline bool timeout_active(const struct io_conn *conn)
52 return conn->timeout && conn->timeout->conn;
55 extern void *io_loop_return;
58 extern struct io_conn *current;
59 static inline void set_current(struct io_conn *conn)
63 static inline bool doing_debug_on(struct io_conn *conn)
65 return io_debug_conn && io_debug_conn(conn);
67 static inline bool doing_debug(void)
72 static inline void set_current(struct io_conn *conn)
75 static inline bool doing_debug_on(struct io_conn *conn)
79 static inline bool doing_debug(void)
85 bool add_listener(struct io_listener *l);
86 bool add_conn(struct io_conn *c);
87 bool add_duplex(struct io_conn *c);
88 void del_listener(struct io_listener *l);
89 void backend_plan_changed(struct io_conn *conn);
90 void backend_add_timeout(struct io_conn *conn, struct timespec ts);
91 void backend_del_timeout(struct io_conn *conn);
92 void backend_del_conn(struct io_conn *conn);
94 void io_ready(struct io_conn *conn);
95 void *do_io_loop(struct io_conn **ready);
96 #endif /* CCAN_IO_BACKEND_H */