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 /* A setting for actions to always run (eg. zero-length reads). */
9 #define POLLALWAYS (((POLLIN|POLLOUT) + 1) & ~((POLLIN|POLLOUT)))
12 void *(*alloc)(size_t size);
13 void *(*realloc)(void *ptr, size_t size);
14 void (*free)(void *ptr);
16 extern struct io_alloc io_alloc;
24 /* Listeners create connections. */
28 /* These are for connections we create. */
29 void (*init)(int fd, void *arg);
37 struct io_plan (*next)(struct io_conn *, void *arg);
41 /* One connection per client. */
45 void (*finish)(struct io_conn *, void *arg);
48 struct io_conn *duplex;
49 struct io_timeout *timeout;
54 static inline bool timeout_active(const struct io_conn *conn)
56 return conn->timeout && conn->timeout->conn;
59 extern void *io_loop_return;
62 extern struct io_conn *current;
63 static inline void set_current(struct io_conn *conn)
67 static inline bool doing_debug_on(struct io_conn *conn)
69 return io_debug_conn && io_debug_conn(conn);
71 static inline bool doing_debug(void)
76 static inline void set_current(struct io_conn *conn)
79 static inline bool doing_debug_on(struct io_conn *conn)
83 static inline bool doing_debug(void)
89 bool add_listener(struct io_listener *l);
90 bool add_conn(struct io_conn *c);
91 bool add_duplex(struct io_conn *c);
92 void del_listener(struct io_listener *l);
93 void backend_plan_changed(struct io_conn *conn);
94 void backend_wait_changed(const void *wait);
95 void backend_add_timeout(struct io_conn *conn, struct timespec ts);
96 void backend_del_timeout(struct io_conn *conn);
97 void backend_del_conn(struct io_conn *conn);
99 void io_ready(struct io_conn *conn);
100 void *do_io_loop(struct io_conn **ready);
101 #endif /* CCAN_IO_BACKEND_H */