X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fio%2Ftest%2Frun-08-read-after-hangup.c;h=14af5ae6373a5afaac958b5b8376fab0c443f7fa;hb=94dd4c2bddd0dc080ad5b85465fa3f45f486967a;hp=95eb651cd7e7f78ee894b8ce35ff664a0320301a;hpb=cf86c1e30648c9b482b92444c39ea6ea0ff936a8;p=ccan diff --git a/ccan/io/test/run-08-read-after-hangup.c b/ccan/io/test/run-08-read-after-hangup.c index 95eb651c..14af5ae6 100644 --- a/ccan/io/test/run-08-read-after-hangup.c +++ b/ccan/io/test/run-08-read-after-hangup.c @@ -9,10 +9,25 @@ static char inbuf[8]; -static struct io_plan wake_it(struct io_conn *conn, struct io_conn *reader) +static struct io_plan *wake_it(struct io_conn *conn, struct io_conn *reader) { - io_wake(reader, io_read(inbuf, 8, io_close, NULL)); - return io_close(conn, NULL); + io_wake(inbuf); + return io_close(conn); +} + +static struct io_plan *read_buf(struct io_conn *conn, void *unused) +{ + return io_read(conn, inbuf, 8, io_close_cb, NULL); +} + +static struct io_plan *init_writer(struct io_conn *conn, struct io_conn *wakeme) +{ + return io_write(conn, "EASYTEST", 8, wake_it, wakeme); +} + +static struct io_plan *init_waiter(struct io_conn *conn, void *unused) +{ + return io_wait(conn, inbuf, read_buf, NULL); } int main(void) @@ -23,11 +38,10 @@ int main(void) plan_tests(3); ok1(pipe(fds) == 0); - conn = io_new_conn(fds[0], io_idle(), NULL, NULL); - io_new_conn(fds[1], io_write("EASYTEST", 8, wake_it, conn), - NULL, NULL); + conn = io_new_conn(NULL, fds[0], init_waiter, NULL); + io_new_conn(conn, fds[1], init_writer, conn); - ok1(io_loop() == NULL); + ok1(io_loop(NULL, NULL) == NULL); ok1(memcmp(inbuf, "EASYTEST", sizeof(inbuf)) == 0); /* This exits depending on whether all tests passed */