X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fio%2Ftest%2Frun-01-start-finish.c;h=297dbc6f9bd9a6ccb15d7af96fb3c49369099e90;hp=a2393d9fa2005cb58e244cc99ebf40974fbc16ce;hb=0f16a4197c94bfa84dad56d0cb9a9c20438d0a45;hpb=0998955055e45ef980a2dfdbd302142269abdd26 diff --git a/ccan/io/test/run-01-start-finish.c b/ccan/io/test/run-01-start-finish.c index a2393d9f..297dbc6f 100644 --- a/ccan/io/test/run-01-start-finish.c +++ b/ccan/io/test/run-01-start-finish.c @@ -6,18 +6,23 @@ #include #include -static struct io_plan *start_ok(struct io_conn *conn, int *state) +#ifndef PORT +#define PORT "65001" +#endif + +static void finish_ok(struct io_conn *conn, int *state) { - ok1(*state == 0); + ok1(*state == 1); (*state)++; - return io_close(conn, NULL); + io_break(state + 1, io_idle()); } -static void finish_ok(struct io_conn *conn, int *state) +static void init_conn(int fd, int *state) { - ok1(*state == 1); + ok1(*state == 0); (*state)++; - io_break(conn, state + 1, NULL, NULL); + io_set_finish(io_new_conn(fd, io_close(NULL, NULL)), finish_ok, state); + } static int make_listen_fd(const char *port, struct addrinfo **info) @@ -61,9 +66,9 @@ 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, start_ok, finish_ok, &state); + l = io_new_listener(fd, init_conn, &state); ok1(l); fflush(stdout); if (!fork()) {