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>
9 static struct io_plan start_ok(struct io_conn *conn, int *state)
13 return io_close(conn, NULL);
16 static void finish_ok(struct io_conn *conn, int *state)
20 io_break(state + 1, NULL, NULL);
23 static void init_conn(int fd, int *state)
25 if (!io_new_conn(fd, start_ok, finish_ok, state))
29 static int make_listen_fd(const char *port, struct addrinfo **info)
32 struct addrinfo *addrinfo, hints;
34 memset(&hints, 0, sizeof(hints));
35 hints.ai_family = AF_UNSPEC;
36 hints.ai_socktype = SOCK_STREAM;
37 hints.ai_flags = AI_PASSIVE;
38 hints.ai_protocol = 0;
40 if (getaddrinfo(NULL, port, &hints, &addrinfo) != 0)
43 fd = socket(addrinfo->ai_family, addrinfo->ai_socktype,
44 addrinfo->ai_protocol);
48 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
49 if (bind(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0) {
53 if (listen(fd, 1) != 0) {
64 struct addrinfo *addrinfo;
65 struct io_listener *l;
68 /* This is how many tests you plan to run */
70 fd = make_listen_fd("65001", &addrinfo);
72 l = io_new_listener(fd, init_conn, &state);
77 fd = socket(addrinfo->ai_family, addrinfo->ai_socktype,
78 addrinfo->ai_protocol);
81 if (connect(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0)
84 freeaddrinfo(addrinfo);
87 freeaddrinfo(addrinfo);
88 ok1(io_loop() == &state + 1);
92 ok1(WIFEXITED(state));
93 ok1(WEXITSTATUS(state) == 0);
95 /* This exits depending on whether all tests passed */