X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fio%2Ftest%2Frun-12-bidir.c;h=3534bc3138f92df5aa6bb57e51849aac26ac6f3b;hp=eb4f4f0551f71804396131ae23f148a87699770d;hb=737705f0c2ec60ea5b51ca55299488d86db37b5d;hpb=0998955055e45ef980a2dfdbd302142269abdd26 diff --git a/ccan/io/test/run-12-bidir.c b/ccan/io/test/run-12-bidir.c index eb4f4f05..3534bc31 100644 --- a/ccan/io/test/run-12-bidir.c +++ b/ccan/io/test/run-12-bidir.c @@ -18,13 +18,13 @@ static void finish_ok(struct io_conn *conn, struct data *d) d->state++; } -static struct io_plan *write_out(struct io_conn *conn, struct data *d) +static struct io_plan write_out(struct io_conn *conn, struct data *d) { d->state++; - return io_write(conn, d->wbuf, sizeof(d->wbuf), io_close, d); + return io_write(d->wbuf, sizeof(d->wbuf), io_close, d); } -static struct io_plan *start_ok(struct io_conn *conn, struct data *d) +static struct io_plan start_ok(struct io_conn *conn, struct data *d) { ok1(d->state == 0); d->state++; @@ -33,7 +33,13 @@ static struct io_plan *start_ok(struct io_conn *conn, struct data *d) memset(d->wbuf, 7, sizeof(d->wbuf)); ok1(io_duplex(conn, write_out, finish_ok, d)); - return io_read(conn, d->buf, sizeof(d->buf), io_close, d); + return io_read(d->buf, sizeof(d->buf), io_close, d); +} + +static void init_conn(int fd, struct data *d) +{ + if (!io_new_conn(fd, start_ok, finish_ok, d)) + abort(); } static int make_listen_fd(const char *port, struct addrinfo **info) @@ -79,7 +85,7 @@ int main(void) d->state = 0; fd = make_listen_fd("65012", &addrinfo); ok1(fd >= 0); - d->l = io_new_listener(fd, start_ok, finish_ok, d); + d->l = io_new_listener(fd, init_conn, d); ok1(d->l); fflush(stdout); if (!fork()) {