X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fio%2Ftest%2Frun-01-start-finish.c;h=074769693f3266843deb2d3d26d98f4e33dca95d;hb=34776d3e9ad7de78778306a2d09c2c95df06c902;hp=03a1e3280bbb1d81908c2767854b4a017ef058e3;hpb=0a2fd289c7bf57d9fc35ad6af36df4bcc694f361;p=ccan diff --git a/ccan/io/test/run-01-start-finish.c b/ccan/io/test/run-01-start-finish.c index 03a1e328..07476969 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_op *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(state + 1, NULL); + if (!io_new_conn(fd, io_close(NULL, NULL), finish_ok, state)) + abort(); } 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()) {