X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fio%2Ftest%2Frun-05-write.c;h=3b0cc72432a30f840e9e0f58f28712dce897f12d;hb=96dcdfbf1a400f7cb43cf3f0761f52fd6de9ff65;hp=ad6760e4f09a465baffc241f4bc3a67658497016;hpb=625bae8f5720d3ad3253ea9b26ad68abcd81bde5;p=ccan diff --git a/ccan/io/test/run-05-write.c b/ccan/io/test/run-05-write.c index ad6760e4..3b0cc724 100644 --- a/ccan/io/test/run-05-write.c +++ b/ccan/io/test/run-05-write.c @@ -6,24 +6,27 @@ #include #include +#define PORT "65005" + struct data { int state; size_t bytes; char *buf; }; -static struct io_plan start_ok(struct io_conn *conn, struct data *d) +static void finish_ok(struct io_conn *conn, struct data *d) { - ok1(d->state == 0); + ok1(d->state == 1); d->state++; - return io_write(conn, d->buf, d->bytes, io_close, d); + io_break(d); } -static void finish_ok(struct io_conn *conn, struct data *d) +static struct io_plan *init_conn(struct io_conn *conn, struct data *d) { - ok1(d->state == 1); + ok1(d->state == 0); d->state++; - io_break(conn, d, NULL, NULL); + io_set_finish(conn, finish_ok, d); + return io_write(conn, d->buf, d->bytes, io_close_cb, d); } static int make_listen_fd(const char *port, struct addrinfo **info) @@ -92,9 +95,9 @@ int main(void) d->bytes = 1024*1024; d->buf = malloc(d->bytes); memset(d->buf, 'a', d->bytes); - fd = make_listen_fd("65005", &addrinfo); + fd = make_listen_fd(PORT, &addrinfo); ok1(fd >= 0); - l = io_new_listener(fd, start_ok, finish_ok, d); + l = io_new_listener(NULL, fd, init_conn, d); ok1(l); fflush(stdout); if (!fork()) { @@ -105,7 +108,7 @@ int main(void) free(d); exit(0); } - ok1(io_loop() == d); + ok1(io_loop(NULL, NULL) == d); ok1(d->state == 2); ok1(wait(&status));