-void io_wake_(struct io_conn *conn,
- struct io_plan *(*fn)(struct io_conn *, void *), void *arg)
+struct io_plan *io_connect_(struct io_conn *conn, const struct addrinfo *addr,
+ struct io_plan *(*next)(struct io_conn *, void *),
+ void *arg)
+{
+ struct io_plan *plan = io_get_plan(conn, IO_IN);
+ int fd = io_conn_fd(conn);
+
+ assert(next);
+
+ /* Save old flags, set nonblock if not already. */
+ plan->u1.s = fcntl(fd, F_GETFL);
+ fcntl(fd, F_SETFL, plan->u1.s | O_NONBLOCK);
+
+ /* Immediate connect can happen. */
+ if (connect(fd, addr->ai_addr, addr->ai_addrlen) == 0)
+ return set_always(conn, plan, next, arg);