+ * io_connect - plan to connect to a listening socket.
+ * @fd: file descriptor.
+ * @addr: where to connect.
+ * @cb: function to call once it's done.
+ * @arg: @cb argument
+ *
+ * This initiates a connection, and creates a plan for
+ * (asynchronously). completing it. Once complete, @len is updated
+ * and the @cb function will be called: on an error, the finish
+ * function is called instead.
+ *
+ * Note that the connect may actually be done immediately.
+ *
+ * Example:
+ * #include <sys/types.h>
+ * #include <sys/socket.h>
+ * #include <netdb.h>
+ *
+ * // Write, then close socket.
+ * static struct io_plan start_write(struct io_conn *conn, void *unused)
+ * {
+ * return io_write("hello", 5, io_close_cb, NULL);
+ * }
+ *
+ * ...
+ *
+ * int fd;
+ * struct addrinfo *addrinfo;
+ *
+ * fd = socket(AF_INET, SOCK_STREAM, 0);
+ * getaddrinfo("localhost", "8111", NULL, &addrinfo);
+ * io_new_conn(fd, io_connect(fd, addrinfo, start_write, NULL));
+ */
+struct addrinfo;
+#define io_connect(fd, addr, cb, arg) \
+ io_debug(io_connect_((fd), (addr), \
+ typesafe_cb_preargs(struct io_plan, void *, \
+ (cb), (arg), \
+ struct io_conn *), \
+ (arg)))
+struct io_plan io_connect_(int fd, const struct addrinfo *addr,
+ struct io_plan (*cb)(struct io_conn *, void*),
+ void *arg);
+
+/**
+ * io_wait - plan to wait for something.
+ * @wait: the address to wait on.
+ * @cb: function to call after waiting.
+ * @arg: @cb argument
+ *
+ * This indicates the connection is idle: io_wake() will be called later to
+ * restart the connection.
+ *
+ * Example:
+ * struct io_conn *sleeper;
+ * unsigned int counter = 0;
+ * sleeper = io_new_conn(open("/dev/null", O_RDONLY),
+ * io_wait(&counter, io_close_cb, NULL));
+ * if (!sleeper)
+ * exit(1);
+ */
+#define io_wait(wait, cb, arg) \
+ io_debug(io_wait_(wait, \
+ typesafe_cb_preargs(struct io_plan, void *, \
+ (cb), (arg), \
+ struct io_conn *), \
+ (arg)))
+
+struct io_plan io_wait_(const void *wait,
+ struct io_plan (*cb)(struct io_conn *, void *),
+ void *arg);
+
+/**
+ * io_timeout - set timeout function if the callback doesn't complete.