X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fio%2Fio.h;h=4468cee3ab0d10d14aacd6cc3cfa3462bc8ec114;hb=f508ed408b230c21341778370ab04def8e7aba3a;hp=b5ffdd243bfd8a1710e551741261bb9159923cff;hpb=13b38a7282c6043d6abe310e5a16d6610ed7a1c1;p=ccan diff --git a/ccan/io/io.h b/ccan/io/io.h index b5ffdd24..4468cee3 100644 --- a/ccan/io/io.h +++ b/ccan/io/io.h @@ -431,6 +431,21 @@ struct io_conn *io_duplex_(struct io_conn *conn, struct io_plan plan); #define io_wake(conn, plan) (io_plan_no_debug(), io_wake_((conn), (plan))) void io_wake_(struct io_conn *conn, struct io_plan plan); +/** + * io_is_idle - is a connection idle? + * + * This can be useful for complex protocols, eg. where you want a connection + * to send something, so you queue it and wake it if it's idle. + * + * Example: + * struct io_conn *sleeper; + * sleeper = io_new_conn(open("/dev/null", O_RDONLY), io_idle()); + * + * assert(io_is_idle(sleeper)); + * io_wake(sleeper, io_write("junk", 4, io_close_cb, NULL)); + */ +bool io_is_idle(const struct io_conn *conn); + /** * io_break - return from io_loop() * @ret: non-NULL value to return from io_loop(). @@ -490,4 +505,25 @@ struct io_plan io_close_cb(struct io_conn *, void *unused); * io_loop(); */ void *io_loop(void); + +/** + * io_conn_fd - get the fd from a connection. + * @conn: the connection. + * + * Sometimes useful, eg for getsockname(). + */ +int io_conn_fd(const struct io_conn *conn); + +/** + * io_set_alloc - set alloc/realloc/free function for io to use. + * @allocfn: allocator function + * @reallocfn: reallocator function, ptr may be NULL, size never 0. + * @freefn: free function + * + * By default io uses malloc/realloc/free, and returns NULL if they fail. + * You can set your own variants here. + */ +void io_set_alloc(void *(*allocfn)(size_t size), + void *(*reallocfn)(void *ptr, size_t size), + void (*freefn)(void *ptr)); #endif /* CCAN_IO_H */