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_op *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);
23 static int make_listen_fd(const char *port, struct addrinfo **info)
26 struct addrinfo *addrinfo, hints;
28 memset(&hints, 0, sizeof(hints));
29 hints.ai_family = AF_UNSPEC;
30 hints.ai_socktype = SOCK_STREAM;
31 hints.ai_flags = AI_PASSIVE;
32 hints.ai_protocol = 0;
34 if (getaddrinfo(NULL, port, &hints, &addrinfo) != 0)
37 fd = socket(addrinfo->ai_family, addrinfo->ai_socktype,
38 addrinfo->ai_protocol);
42 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
43 if (bind(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0) {
47 if (listen(fd, 1) != 0) {
58 struct addrinfo *addrinfo;
59 struct io_listener *l;
62 /* This is how many tests you plan to run */
64 fd = make_listen_fd("65001", &addrinfo);
66 l = io_new_listener(fd, start_ok, finish_ok, &state);
71 fd = socket(addrinfo->ai_family, addrinfo->ai_socktype,
72 addrinfo->ai_protocol);
75 if (connect(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0)
78 freeaddrinfo(addrinfo);
81 freeaddrinfo(addrinfo);
82 ok1(io_loop() == &state + 1);
86 ok1(WIFEXITED(state));
87 ok1(WEXITSTATUS(state) == 0);
89 /* This exits depending on whether all tests passed */