]> git.ozlabs.org Git - ccan/blobdiff - ccan/io/test/run-01-start-finish.c
ccan/io: generic init function for listening connections.
[ccan] / ccan / io / test / run-01-start-finish.c
index a2393d9fa2005cb58e244cc99ebf40974fbc16ce..53c07f24b4a07b0267953966b2a37af6242ea158 100644 (file)
@@ -6,7 +6,7 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
-static struct io_plan *start_ok(struct io_conn *conn, int *state)
+static struct io_plan start_ok(struct io_conn *conn, int *state)
 {
        ok1(*state == 0);
        (*state)++;
@@ -17,7 +17,13 @@ static void finish_ok(struct io_conn *conn, int *state)
 {
        ok1(*state == 1);
        (*state)++;
-       io_break(conn, state + 1, NULL, NULL);
+       io_break(state + 1, NULL, NULL);
+}
+
+static void init_conn(int fd, int *state)
+{
+       if (!io_new_conn(fd, start_ok, finish_ok, state))
+               abort();
 }
 
 static int make_listen_fd(const char *port, struct addrinfo **info)
@@ -63,7 +69,7 @@ int main(void)
        plan_tests(9);
        fd = make_listen_fd("65001", &addrinfo);
        ok1(fd >= 0);
-       l = io_new_listener(fd, start_ok, finish_ok, &state);
+       l = io_new_listener(fd, init_conn, &state);
        ok1(l);
        fflush(stdout);
        if (!fork()) {