X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fio%2Fio.h;h=0318aef300873fa71104e0a2b630ad28e93e7065;hb=83d4e1285dec87fa54043377eafd1b3bf9b0c53f;hp=b5ffdd243bfd8a1710e551741261bb9159923cff;hpb=13b38a7282c6043d6abe310e5a16d6610ed7a1c1;p=ccan diff --git a/ccan/io/io.h b/ccan/io/io.h index b5ffdd24..0318aef3 100644 --- a/ccan/io/io.h +++ b/ccan/io/io.h @@ -394,7 +394,7 @@ bool io_timeout_(struct io_conn *conn, struct timespec ts, * to have two connections for the same fd, and use one for read * operations and one for write. * - * You must io_close() both of them to close the fd. + * Returning io_close() on one will close both fds! * * Example: * static void setup_read_write(int fd, @@ -490,4 +490,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 */