X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fio%2Ftest%2Frun-01-start-finish.c;h=d8a24a52fe42b35e1ddf3a740b3d31d151f8165c;hp=53c07f24b4a07b0267953966b2a37af6242ea158;hb=490b63852f281f0d72eb6f6dfa5e0dce36bcbe0d;hpb=737705f0c2ec60ea5b51ca55299488d86db37b5d diff --git a/ccan/io/test/run-01-start-finish.c b/ccan/io/test/run-01-start-finish.c index 53c07f24..d8a24a52 100644 --- a/ccan/io/test/run-01-start-finish.c +++ b/ccan/io/test/run-01-start-finish.c @@ -6,24 +6,25 @@ #include #include -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 int expected_fd; static void finish_ok(struct io_conn *conn, int *state) { ok1(*state == 1); + ok1(io_conn_fd(conn) == expected_fd); (*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)++; + expected_fd = fd; + io_set_finish(io_new_conn(fd, io_close()), finish_ok, state); } static int make_listen_fd(const char *port, struct addrinfo **info) @@ -66,8 +67,8 @@ int main(void) int fd; /* This is how many tests you plan to run */ - plan_tests(9); - fd = make_listen_fd("65001", &addrinfo); + plan_tests(10); + fd = make_listen_fd(PORT, &addrinfo); ok1(fd >= 0); l = io_new_listener(fd, init_conn, &state); ok1(l);