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>
11 static int make_listen_fd(const char *port, struct addrinfo **info)
14 struct addrinfo *addrinfo, hints;
16 memset(&hints, 0, sizeof(hints));
17 hints.ai_family = AF_UNSPEC;
18 hints.ai_socktype = SOCK_STREAM;
19 hints.ai_flags = AI_PASSIVE;
20 hints.ai_protocol = 0;
22 if (getaddrinfo(NULL, port, &hints, &addrinfo) != 0)
25 fd = socket(addrinfo->ai_family, addrinfo->ai_socktype,
26 addrinfo->ai_protocol);
30 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
31 if (bind(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0) {
35 if (listen(fd, 1) != 0) {
45 struct addrinfo *addrinfo = NULL;
48 /* This is how many tests you plan to run */
50 fd = make_listen_fd(PORT, &addrinfo);
51 freeaddrinfo(addrinfo);
52 io_new_listener(NULL, fd, io_never, NULL);
54 /* Anyone could do this; a child doing it will cause poll to return
56 shutdown(fd, SHUT_RDWR);
57 ok1(io_loop(NULL, NULL) == NULL);
59 /* This exits depending on whether all tests passed */