X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fio%2Ftest%2Frun-03-readpartial.c;h=2d15c2f51c0fb9982d51d704a3411d0710ccf9d9;hp=a7d0ae3161aa674cc7b22a23ec16c1148cb1cca8;hb=94dd4c2bddd0dc080ad5b85465fa3f45f486967a;hpb=737705f0c2ec60ea5b51ca55299488d86db37b5d diff --git a/ccan/io/test/run-03-readpartial.c b/ccan/io/test/run-03-readpartial.c index a7d0ae31..2d15c2f5 100644 --- a/ccan/io/test/run-03-readpartial.c +++ b/ccan/io/test/run-03-readpartial.c @@ -6,31 +6,32 @@ #include #include +#ifndef PORT +#define PORT "65003" +#endif + struct data { int state; size_t bytes; char buf[4]; }; -static struct io_plan start_ok(struct io_conn *conn, struct data *d) -{ - ok1(d->state == 0); - d->state++; - d->bytes = sizeof(d->buf); - return io_read_partial(d->buf, &d->bytes, io_close, d); -} - static void finish_ok(struct io_conn *conn, struct data *d) { ok1(d->state == 1); d->state++; - io_break(d, NULL, NULL); + io_break(d); } -static void init_conn(int fd, struct data *d) +static struct io_plan *init_conn(struct io_conn *conn, struct data *d) { - if (!io_new_conn(fd, start_ok, finish_ok, d)) - abort(); + ok1(d->state == 0); + d->state++; + + io_set_finish(conn, finish_ok, d); + + return io_read_partial(conn, d->buf, sizeof(d->buf), &d->bytes, + io_close_cb, d); } static int make_listen_fd(const char *port, struct addrinfo **info) @@ -93,9 +94,9 @@ int main(void) /* This is how many tests you plan to run */ plan_tests(22); d->state = 0; - fd = make_listen_fd("65003", &addrinfo); + fd = make_listen_fd(PORT, &addrinfo); ok1(fd >= 0); - l = io_new_listener(fd, init_conn, d); + l = io_new_listener(NULL, fd, init_conn, d); ok1(l); fflush(stdout); if (!fork()) { @@ -105,7 +106,7 @@ int main(void) free(d); exit(0); } - ok1(io_loop() == d); + ok1(io_loop(NULL, NULL) == d); ok1(d->state == 2); ok1(d->bytes > 0); ok1(d->bytes <= sizeof(d->buf)); @@ -124,7 +125,7 @@ int main(void) exit(0); } d->state = 0; - ok1(io_loop() == d); + ok1(io_loop(NULL, NULL) == d); ok1(d->state == 2); ok1(d->bytes > 0); ok1(d->bytes <= strlen("hi"));