]> git.ozlabs.org Git - ccan/blobdiff - 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
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 (file)
index 0000000..95eb651
--- /dev/null
@@ -0,0 +1,35 @@
+#include <ccan/io/io.h>
+/* Include the C files directly. */
+#include <ccan/io/poll.c>
+#include <ccan/io/io.c>
+#include <ccan/tap/tap.h>
+#include <sys/wait.h>
+#include <stdio.h>
+#include <signal.h>
+
+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();
+}