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 void finish_ok(struct io_conn *conn, int *state)
13 io_break(state + 1, io_idle());
16 static void init_conn(int fd, int *state)
20 if (!io_new_conn(fd, io_close(NULL, NULL), finish_ok, state))
24 static int make_listen_fd(const char *port, struct addrinfo **info)
27 struct addrinfo *addrinfo, hints;
29 memset(&hints, 0, sizeof(hints));
30 hints.ai_family = AF_UNSPEC;
31 hints.ai_socktype = SOCK_STREAM;
32 hints.ai_flags = AI_PASSIVE;
33 hints.ai_protocol = 0;
35 if (getaddrinfo(NULL, port, &hints, &addrinfo) != 0)
38 fd = socket(addrinfo->ai_family, addrinfo->ai_socktype,
39 addrinfo->ai_protocol);
43 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
44 if (bind(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0) {
48 if (listen(fd, 1) != 0) {
59 struct addrinfo *addrinfo;
60 struct io_listener *l;
63 /* This is how many tests you plan to run */
65 fd = make_listen_fd("65001", &addrinfo);
67 l = io_new_listener(fd, init_conn, &state);
72 fd = socket(addrinfo->ai_family, addrinfo->ai_socktype,
73 addrinfo->ai_protocol);
76 if (connect(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0)
79 freeaddrinfo(addrinfo);
82 freeaddrinfo(addrinfo);
83 ok1(io_loop() == &state + 1);
87 ok1(WIFEXITED(state));
88 ok1(WEXITSTATUS(state) == 0);
90 /* This exits depending on whether all tests passed */