137 int socktype = ((
type & 0xff) ==
USOCK_TCP) ? SOCK_STREAM : SOCK_DGRAM;
139 struct addrinfo *result, *rp;
140 struct addrinfo hints = {
143 .ai_socktype = socktype,
144 .ai_flags = AI_ADDRCONFIG
148 struct addrinfo *rp_v6 = NULL;
149 struct addrinfo *rp_v4 = NULL;
150 struct pollfd pfds[2] = {
151 { .
fd = -1, .events = POLLOUT },
152 { .fd = -1, .events = POLLOUT },
157 if (getaddrinfo(host, service, &hints, &result))
160 if (timeout <= 0 ||
server) {
165 for (rp = result; rp != NULL; rp = rp->ai_next) {
166 if (rp->ai_family == AF_INET6 && !rp_v6)
168 if (rp->ai_family == AF_INET && !rp_v4)
172 if (!rp_v6 && !rp_v4)
178 rp->ai_addrlen, rp->ai_family,
180 if (pfds[0].
fd < 0) {
199 rp->ai_addrlen, rp->ai_family,
201 if (pfds[1].
fd < 0) {
210 poll_restart(pfds + !rp_v6, !!rp_v6 + !!rp_v4, timeout);
211 if (pfds[0].revents & POLLOUT) {
217 if (pfds[1].revents & POLLOUT) {
224 for (i = 0; i < 2; i++) {
226 if (
fd >= 0 &&
fd != sock)
231 fcntl(sock, F_SETFL, fcntl(sock, F_GETFL) & ~O_NONBLOCK);
233 if (addr && sock >= 0)
234 memcpy(addr, rp->ai_addr, rp->ai_addrlen);
236 freeaddrinfo(result);
static int poll_restart(struct pollfd *fds, int nfds, int timeout)
static int usock_inet_notimeout(int type, struct addrinfo *result, void *addr)