X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fio%2Ftest%2Frun-04-writepartial.c;h=5c1f5e015da50707999d77ee037b93853e8653bb;hb=cdf62dce7077a9f9a818edbb67d31d033cbb73c6;hp=87fa8d9d0b22fef5b01da4d9d51473e602b4fada;hpb=0998955055e45ef980a2dfdbd302142269abdd26;p=ccan diff --git a/ccan/io/test/run-04-writepartial.c b/ccan/io/test/run-04-writepartial.c index 87fa8d9d..5c1f5e01 100644 --- a/ccan/io/test/run-04-writepartial.c +++ b/ccan/io/test/run-04-writepartial.c @@ -6,24 +6,30 @@ #include #include +#ifndef PORT +#define PORT "65004" +#endif + 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_partial(conn, d->buf, &d->bytes, io_close, d); + io_break(d, io_never()); } -static void finish_ok(struct io_conn *conn, struct data *d) +static void init_conn(int fd, struct data *d) { - ok1(d->state == 1); + ok1(d->state == 0); d->state++; - io_break(conn, d, NULL, NULL); + io_set_finish(io_new_conn(fd, + io_write_partial(d->buf, &d->bytes, io_close_cb, d)), + finish_ok, d); } static int make_listen_fd(const char *port, struct addrinfo **info) @@ -89,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("65004", &addrinfo); + fd = make_listen_fd(PORT, &addrinfo); ok1(fd >= 0); - l = io_new_listener(fd, start_ok, finish_ok, d); + l = io_new_listener(fd, init_conn, d); ok1(l); fflush(stdout); if (!fork()) {