]> git.ozlabs.org Git - ccan/blob - ccan/io/test/run-08-read-after-hangup.c
ccan/io: test read after hangup.
[ccan] / ccan / io / test / run-08-read-after-hangup.c
1 #include <ccan/io/io.h>
2 /* Include the C files directly. */
3 #include <ccan/io/poll.c>
4 #include <ccan/io/io.c>
5 #include <ccan/tap/tap.h>
6 #include <sys/wait.h>
7 #include <stdio.h>
8 #include <signal.h>
9
10 static char inbuf[8];
11
12 static struct io_plan wake_it(struct io_conn *conn, struct io_conn *reader)
13 {
14         io_wake(reader, io_read(inbuf, 8, io_close, NULL));
15         return io_close(conn, NULL);
16 }
17
18 int main(void)
19 {
20         int fds[2];
21         struct io_conn *conn;
22
23         plan_tests(3);
24
25         ok1(pipe(fds) == 0);
26         conn = io_new_conn(fds[0], io_idle(), NULL, NULL);
27         io_new_conn(fds[1], io_write("EASYTEST", 8, wake_it, conn),
28                     NULL, NULL);
29
30         ok1(io_loop() == NULL);
31         ok1(memcmp(inbuf, "EASYTEST", sizeof(inbuf)) == 0);
32
33         /* This exits depending on whether all tests passed */
34         return exit_status();
35 }