return conn;
}
-bool io_timeout_(struct io_conn *conn, struct timespec ts,
+bool io_timeout_(struct io_conn *conn, struct timerel t,
struct io_plan (*cb)(struct io_conn *, void *), void *arg)
{
assert(cb);
conn->timeout->next = cb;
conn->timeout->next_arg = arg;
- backend_add_timeout(conn, ts);
+ backend_add_timeout(conn, t);
return true;
}
if (err == 0) {
/* Restore blocking if it was initially. */
- fcntl(fd, F_SETFD, plan->u1.s);
+ fcntl(fd, F_SETFL, plan->u1.s);
return 1;
- }
- return 0;
+ } else if (err == EINPROGRESS)
+ return 0;
+
+ errno = err;
+ return -1;
}
struct io_plan io_connect_(int fd, const struct addrinfo *addr,
plan.next_arg = arg;
/* Save old flags, set nonblock if not already. */
- plan.u1.s = fcntl(fd, F_GETFD);
- fcntl(fd, F_SETFD, plan.u1.s | O_NONBLOCK);
+ 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) {
void io_close_other(struct io_conn *conn)
{
- conn->plan = io_close_();
- backend_plan_changed(conn);
+ /* Don't close if already closing! */
+ if (conn->plan.next) {
+ conn->plan = io_close_();
+ backend_plan_changed(conn);
+ }
}
/* Exit the loop, returning this (non-NULL) arg. */