X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fio%2Ftest%2Frun-01-start-finish.c;h=04952db88e5ce9e3d65c9cadb57fee5e4730e001;hp=53c07f24b4a07b0267953966b2a37af6242ea158;hb=0ce52c7ca42c2b3a6458cac348f5a8b96d7f1b62;hpb=737705f0c2ec60ea5b51ca55299488d86db37b5d diff --git a/ccan/io/test/run-01-start-finish.c b/ccan/io/test/run-01-start-finish.c index 53c07f24..04952db8 100644 --- a/ccan/io/test/run-01-start-finish.c +++ b/ccan/io/test/run-01-start-finish.c @@ -6,24 +6,32 @@ #include #include -static struct io_plan start_ok(struct io_conn *conn, int *state) -{ - ok1(*state == 0); - (*state)++; - return io_close(conn, NULL); -} +#ifdef DEBUG_CONN +#define PORT "64001" +#else +#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); } -static void init_conn(int fd, int *state) +static struct io_plan *init_conn(struct io_conn *conn, int *state) { - if (!io_new_conn(fd, start_ok, finish_ok, state)) - abort(); +#ifdef DEBUG_CONN + io_set_debug(conn, true); +#endif + ok1(*state == 0); + (*state)++; + expected_fd = io_conn_fd(conn); + io_set_finish(conn, finish_ok, state); + + return io_close(conn); } static int make_listen_fd(const char *port, struct addrinfo **info) @@ -61,15 +69,15 @@ static int make_listen_fd(const char *port, struct addrinfo **info) int main(void) { int state = 0; - struct addrinfo *addrinfo; + struct addrinfo *addrinfo = NULL; struct io_listener *l; 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); + l = io_new_listener(NULL, fd, init_conn, &state); ok1(l); fflush(stdout); if (!fork()) { @@ -85,7 +93,7 @@ int main(void) exit(0); } freeaddrinfo(addrinfo); - ok1(io_loop() == &state + 1); + ok1(io_loop(NULL, NULL) == &state + 1); ok1(state == 2); io_close_listener(l); ok1(wait(&state));