X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fio%2Ftest%2Frun-01-start-finish.c;h=3ee659471847d73addc4c4e57b26e3eb6d2086c5;hp=b879a2c832fee1bcc0253bac85e6bb8a2eb3b692;hb=f7ab2c65d40839a327e50876dc2708ab7b11aa52;hpb=733b09fa8b6083949ff62795e54851aa282d510c diff --git a/ccan/io/test/run-01-start-finish.c b/ccan/io/test/run-01-start-finish.c index b879a2c8..3ee65947 100644 --- a/ccan/io/test/run-01-start-finish.c +++ b/ccan/io/test/run-01-start-finish.c @@ -6,18 +6,25 @@ #include #include -static struct io_plan start_ok(struct io_conn *conn, int *state) +#ifndef PORT +#define PORT "65001" +#endif +static int expected_fd; + +static void finish_ok(struct io_conn *conn, int *state) { - ok1(*state == 0); + ok1(*state == 1); + ok1(io_conn_fd(conn) == expected_fd); (*state)++; - return io_close(conn, NULL); + io_break(state + 1, io_never()); } -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(state + 1, NULL, NULL); + 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) @@ -60,10 +67,10 @@ 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, start_ok, finish_ok, &state); + l = io_new_listener(fd, init_conn, &state); ok1(l); fflush(stdout); if (!fork()) {