]> git.ozlabs.org Git - ccan/blobdiff - ccan/io/test/run-19-always.c
ccan/io: implement timeouts.
[ccan] / ccan / io / test / run-19-always.c
index 1805f79f6619b310834f191b36161e33aba741b0..63eb34e61fb4ec443be0c88977acaea55402f52e 100644 (file)
@@ -20,21 +20,22 @@ static void finish_ok(struct io_conn *conn, struct data *d)
 {
        ok1(d->state == 1);
        d->state++;
-       io_break(d, io_never());
+       io_break(d);
 }
 
-static struct io_plan write_buf(struct io_conn *conn, struct data *d)
+static struct io_plan *write_buf(struct io_conn *conn, struct data *d)
 {
-       return io_write(d->buf, d->bytes, io_close_cb, d);
+       return io_write(conn, d->buf, d->bytes, io_close_cb, d);
 }
 
-static void init_conn(int fd, struct data *d)
+static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
        ok1(d->state == 0);
        d->state++;
+       io_set_finish(conn, finish_ok, d);
+
        /* Empty read should run immediately... */
-       io_set_finish(io_new_conn(fd, io_read(NULL, 0, write_buf, d)),
-                     finish_ok, d);
+       return io_read(conn, NULL, 0, write_buf, d);
 }
 
 static int make_listen_fd(const char *port, struct addrinfo **info)
@@ -105,7 +106,7 @@ int main(void)
        memset(d->buf, 'a', d->bytes);
        fd = make_listen_fd(PORT, &addrinfo);
        ok1(fd >= 0);
-       l = io_new_listener(fd, init_conn, d);
+       l = io_new_listener(NULL, fd, init_conn, d);
        ok1(l);
        fflush(stdout);
        if (!fork()) {
@@ -116,7 +117,7 @@ int main(void)
                free(d);
                exit(0);
        }
-       ok1(io_loop() == d);
+       ok1(io_loop(NULL, NULL) == d);
        ok1(d->state == 2);
 
        ok1(wait(&status));