X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fio%2Ftest%2Frun-08-read-after-hangup.c;fp=ccan%2Fio%2Ftest%2Frun-08-read-after-hangup.c;h=95eb651cd7e7f78ee894b8ce35ff664a0320301a;hb=cf86c1e30648c9b482b92444c39ea6ea0ff936a8;hp=0000000000000000000000000000000000000000;hpb=d0458a433876acc01b48f74c1c3b966bbc29de57;p=ccan diff --git a/ccan/io/test/run-08-read-after-hangup.c b/ccan/io/test/run-08-read-after-hangup.c new file mode 100644 index 00000000..95eb651c --- /dev/null +++ b/ccan/io/test/run-08-read-after-hangup.c @@ -0,0 +1,35 @@ +#include +/* Include the C files directly. */ +#include +#include +#include +#include +#include +#include + +static char inbuf[8]; + +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); +} + +int main(void) +{ + int fds[2]; + struct io_conn *conn; + + 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); + + ok1(io_loop() == NULL); + ok1(memcmp(inbuf, "EASYTEST", sizeof(inbuf)) == 0); + + /* This exits depending on whether all tests passed */ + return exit_status(); +}