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>
13 static void finish_ok(struct io_conn *conn, int *state)
17 io_break(state + 1, io_idle());
20 static void init_conn(int fd, int *state)
24 io_set_finish(io_new_conn(fd, io_close(NULL, NULL)), finish_ok, state);
28 static int make_listen_fd(const char *port, struct addrinfo **info)
31 struct addrinfo *addrinfo, hints;
33 memset(&hints, 0, sizeof(hints));
34 hints.ai_family = AF_UNSPEC;
35 hints.ai_socktype = SOCK_STREAM;
36 hints.ai_flags = AI_PASSIVE;
37 hints.ai_protocol = 0;
39 if (getaddrinfo(NULL, port, &hints, &addrinfo) != 0)
42 fd = socket(addrinfo->ai_family, addrinfo->ai_socktype,
43 addrinfo->ai_protocol);
47 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
48 if (bind(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0) {
52 if (listen(fd, 1) != 0) {
63 struct addrinfo *addrinfo;
64 struct io_listener *l;
67 /* This is how many tests you plan to run */
69 fd = make_listen_fd(PORT, &addrinfo);
71 l = io_new_listener(fd, init_conn, &state);
76 fd = socket(addrinfo->ai_family, addrinfo->ai_socktype,
77 addrinfo->ai_protocol);
80 if (connect(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0)
83 freeaddrinfo(addrinfo);
86 freeaddrinfo(addrinfo);
87 ok1(io_loop() == &state + 1);
91 ok1(WIFEXITED(state));
92 ok1(WEXITSTATUS(state) == 0);
94 /* This exits depending on whether all tests passed */