]> git.ozlabs.org Git - ccan/blobdiff - ccan/io/test/run-01-start-finish.c
io: io_set_alloc()
[ccan] / ccan / io / test / run-01-start-finish.c
index 53c07f24b4a07b0267953966b2a37af6242ea158..a63baf7706c12970ed25b27e84c0cec76328c65d 100644 (file)
@@ -6,24 +6,22 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
-static struct io_plan start_ok(struct io_conn *conn, int *state)
-{
-       ok1(*state == 0);
-       (*state)++;
-       return io_close(conn, NULL);
-}
+#ifndef PORT
+#define PORT "65001"
+#endif
 
 static void finish_ok(struct io_conn *conn, int *state)
 {
        ok1(*state == 1);
        (*state)++;
-       io_break(state + 1, NULL, NULL);
+       io_break(state + 1, io_idle());
 }
 
 static void init_conn(int fd, int *state)
 {
-       if (!io_new_conn(fd, start_ok, finish_ok, state))
-               abort();
+       ok1(*state == 0);
+       (*state)++;
+       io_set_finish(io_new_conn(fd, io_close()), finish_ok, state);
 }
 
 static int make_listen_fd(const char *port, struct addrinfo **info)
@@ -67,7 +65,7 @@ int main(void)
 
        /* This is how many tests you plan to run */
        plan_tests(9);
-       fd = make_listen_fd("65001", &addrinfo);
+       fd = make_listen_fd(PORT, &addrinfo);
        ok1(fd >= 0);
        l = io_new_listener(fd, init_conn, &state);
        ok1(l);