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>
7 static struct io_conn *in_conn;
9 static struct io_plan *in_conn_done(struct io_conn *conn, void *unused)
11 ok1(!io_plan_in_started(conn));
12 return io_close(conn);
15 static struct io_plan *init_in_conn(struct io_conn *conn, char *buf)
17 ok1(!io_plan_in_started(conn));
18 return io_read(conn, buf, 2, in_conn_done, NULL);
21 static int do_nothing(int fd, struct io_plan_arg *arg)
26 static struct io_plan *dummy_write(struct io_conn *conn,
27 struct io_plan *(*next)
28 (struct io_conn *, void *),
31 io_plan_arg(conn, IO_OUT);
32 return io_set_plan(conn, IO_OUT, do_nothing, next, next_arg);
35 static struct io_plan *out_post_write(struct io_conn *conn, void *unused)
37 /* It might not have started yet: try again. */
38 if (!io_plan_in_started(in_conn))
39 return dummy_write(conn, out_post_write, NULL);
40 ok1(io_plan_in_started(in_conn));
42 /* Final write, then close */
43 return io_write(conn, "2", 1, io_close_cb, NULL);
46 static struct io_plan *init_out_conn(struct io_conn *conn, void *unused)
48 ok1(!io_plan_in_started(in_conn));
49 return io_write(conn, "1", 1, out_post_write, NULL);
55 const tal_t *ctx = tal(NULL, char);
56 char *buf = tal_arr(ctx, char, 3);
58 /* This is how many tests you plan to run */
66 in_conn = io_new_conn(ctx, fds[0], init_in_conn, buf);
67 io_new_conn(ctx, fds[1], init_out_conn, NULL);
70 ok1(strcmp(buf, "12") == 0);
73 /* This exits depending on whether all tests passed */