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()), finish_ok, state);
27 static int make_listen_fd(const char *port, struct addrinfo **info)
30 struct addrinfo *addrinfo, hints;
32 memset(&hints, 0, sizeof(hints));
33 hints.ai_family = AF_UNSPEC;
34 hints.ai_socktype = SOCK_STREAM;
35 hints.ai_flags = AI_PASSIVE;
36 hints.ai_protocol = 0;
38 if (getaddrinfo(NULL, port, &hints, &addrinfo) != 0)
41 fd = socket(addrinfo->ai_family, addrinfo->ai_socktype,
42 addrinfo->ai_protocol);
46 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
47 if (bind(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0) {
51 if (listen(fd, 1) != 0) {
62 struct addrinfo *addrinfo;
63 struct io_listener *l;
66 /* This is how many tests you plan to run */
68 fd = make_listen_fd(PORT, &addrinfo);
70 l = io_new_listener(fd, init_conn, &state);
75 fd = socket(addrinfo->ai_family, addrinfo->ai_socktype,
76 addrinfo->ai_protocol);
79 if (connect(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0)
82 freeaddrinfo(addrinfo);
85 freeaddrinfo(addrinfo);
86 ok1(io_loop() == &state + 1);
90 ok1(WIFEXITED(state));
91 ok1(WEXITSTATUS(state) == 0);
93 /* This exits depending on whether all tests passed */