1 #include <ccan/io/fdpass/fdpass.h>
2 /* Include the C files directly. */
3 #include <ccan/io/fdpass/fdpass.c>
4 #include <ccan/tap/tap.h>
6 #include <sys/socket.h>
8 static struct io_plan *try_reading(struct io_conn *conn, int *fd)
11 ok1(read(*fd, buf, sizeof(buf)) == sizeof(buf));
12 ok1(memcmp(buf, "hello!", sizeof(buf)) == 0);
13 return io_close(conn);
16 static struct io_plan *get_fd(struct io_conn *conn, void *unused)
18 int *fd = tal(conn, int);
19 return io_recv_fd(conn, fd, try_reading, fd);
22 static struct io_plan *try_writing(struct io_conn *conn, int *pfd)
25 ok1(write(pfd[1], "hello!", 6) == 6);
26 return io_close(conn);
29 static struct io_plan *send_fd(struct io_conn *conn, int *pfd)
31 return io_send_fd(conn, pfd[0], true, try_writing, pfd);
40 ok1(socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == 0);
43 /* Pass read end of pipe to ourselves, test. */
44 io_new_conn(NULL, sv[0], get_fd, NULL);
45 io_new_conn(NULL, sv[1], send_fd, pfd);
49 /* This exits depending on whether all tests passed */