X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fio%2Fio.h;h=bcdb11fdd0e0c1f1e9a08aac55a13e0afe888d92;hp=558a8769e1428355c254af670790d01f5ccda09e;hb=12ab811533406e22b78ce8b227474f1056375ae4;hpb=075120f34490f1b7c55a4ebdc70bbcff17e55a84 diff --git a/ccan/io/io.h b/ccan/io/io.h index 558a8769..bcdb11fd 100644 --- a/ccan/io/io.h +++ b/ccan/io/io.h @@ -290,6 +290,29 @@ struct io_plan io_write_partial_(const void *data, size_t *len, struct io_plan (*cb)(struct io_conn *, void*), void *arg); +/** + * io_always - plan to immediately call next callback. + * @cb: function to call. + * @arg: @cb argument + * + * Sometimes it's neater to plan a callback rather than call it directly; + * for example, if you only need to read data for one path and not another. + * + * Example: + * static void start_conn_with_nothing(int fd) + * { + * // Silly example: close on next time around loop. + * io_new_conn(fd, io_always(io_close_cb, NULL)); + * } + */ +#define io_always(cb, arg) \ + io_debug(io_always_(typesafe_cb_preargs(struct io_plan, void *, \ + (cb), (arg), \ + struct io_conn *), \ + (arg))) +struct io_plan io_always_(struct io_plan (*cb)(struct io_conn *, void *), + void *arg); + /** * io_connect - plan to connect to a listening socket. * @fd: file descriptor.