+/**
+ * io_set_finish - set finish function on a connection.
+ * @conn: the connection.
+ * @finish: the function to call when it's closed or fails.
+ * @arg: the argument to @finish.
+ *
+ * @finish will be called when an I/O operation fails, or you call
+ * io_close() on the connection. errno will be set to the value
+ * after the failed I/O, or at the call to io_close(). The fd
+ * will be closed before @finish is called.
+ *
+ * Example:
+ * static void finish(struct io_conn *conn, const char *msg)
+ * {
+ * // errno is not 0 after success, so this is a bit useless.
+ * printf("Conn %p closed with errno %i (%s)\n", conn, errno, msg);
+ * }
+ *
+ * // Dumb init function to print string and tell conn to close.
+ * static struct io_plan *conn_init(struct io_conn *conn, const char *msg)
+ * {
+ * io_set_finish(conn, finish, msg);
+ * return io_close(conn);
+ * }
+ */
+#define io_set_finish(conn, finish, arg) \
+ io_set_finish_((conn), \
+ typesafe_cb_preargs(void, void *, \
+ (finish), (arg), \
+ struct io_conn *), \
+ (void *)(arg))
+void io_set_finish_(struct io_conn *conn,
+ void (*finish)(struct io_conn *, void *),
+ void *arg);
+
+