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_100(struct io_conn *conn, int *state)
20 static void finish_EBADF(struct io_conn *conn, int *state)
25 io_break(state + 1, io_close());
28 static void init_conn(int fd, int *state)
33 io_set_finish(io_new_conn(fd, io_close()), finish_100, state);
39 io_set_finish(io_new_conn(fd, io_read(state, 0,
45 static int make_listen_fd(const char *port, struct addrinfo **info)
48 struct addrinfo *addrinfo, hints;
50 memset(&hints, 0, sizeof(hints));
51 hints.ai_family = AF_UNSPEC;
52 hints.ai_socktype = SOCK_STREAM;
53 hints.ai_flags = AI_PASSIVE;
54 hints.ai_protocol = 0;
56 if (getaddrinfo(NULL, port, &hints, &addrinfo) != 0)
59 fd = socket(addrinfo->ai_family, addrinfo->ai_socktype,
60 addrinfo->ai_protocol);
64 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
65 if (bind(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0) {
69 if (listen(fd, 1) != 0) {
80 struct addrinfo *addrinfo;
81 struct io_listener *l;
84 /* This is how many tests you plan to run */
86 fd = make_listen_fd(PORT, &addrinfo);
88 l = io_new_listener(fd, init_conn, &state);
93 fd = socket(addrinfo->ai_family, addrinfo->ai_socktype,
94 addrinfo->ai_protocol);
97 if (connect(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0)
100 fd = socket(addrinfo->ai_family, addrinfo->ai_socktype,
101 addrinfo->ai_protocol);
104 if (connect(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0)
107 freeaddrinfo(addrinfo);
110 freeaddrinfo(addrinfo);
111 ok1(io_loop() == &state + 1);
113 io_close_listener(l);
115 ok1(WIFEXITED(state));
116 ok1(WEXITSTATUS(state) == 0);
118 /* This exits depending on whether all tests passed */
119 return exit_status();