+#ifndef HAVE_POLL
+ if (fds[nfds] > max_fd)
+ max_fd = fds[nfds];
+#endif /* !HAVE_POLL */
+
+ addrs[nfds] = addrlist;
+ nfds ++;
+ }
+
+#ifdef O_NONBLOCK
+ DEBUG_puts("1httpAddrConnect2: Finishing async connect()");
+
+ for (remaining = msec; remaining > 0; remaining -= 250)
+ {
+ do
+ {
+ if (cancel && *cancel)
+ {
+ /*
+ * Close this socket and return...
+ */
+
+ DEBUG_puts("1httpAddrConnect2: Canceled connect()");
+
+ while (nfds > 0)
+ {
+ nfds --;
+ httpAddrClose(NULL, fds[nfds]);
+ }
+
+ *sock = -1;
+
+ return (NULL);
+ }
+
+# ifdef HAVE_POLL
+ for (i = 0; i < nfds; i ++)
+ {
+ pfds[i].fd = fds[i];
+ pfds[i].events = POLLIN | POLLOUT;
+ }
+
+ result = poll(pfds, (nfds_t)nfds, remaining > 250 ? 250 : remaining);
+
+ DEBUG_printf(("1httpAddrConnect2: poll() returned %d (%d)", result, errno));
+
+# else
+ FD_ZERO(&input_set);
+ for (i = 0; i < nfds; i ++)
+ FD_SET(fds[i], &input_set);
+ output_set = input_set;
+
+ timeout.tv_sec = 0;
+ timeout.tv_usec = (remaining > 250 ? 250 : remaining) * 1000;
+
+ result = select(max_fd + 1, &input_set, &output_set, NULL, &timeout);
+
+ DEBUG_printf(("1httpAddrConnect2: select() returned %d (%d)", result, errno));
+# endif /* HAVE_POLL */
+ }
+# ifdef WIN32
+ while (result < 0 && (WSAGetLastError() == WSAEINTR || WSAGetLastError() == WSAEWOULDBLOCK));
+# else
+ while (result < 0 && (errno == EINTR || errno == EAGAIN));
+# endif /* WIN32 */
+
+ if (result > 0)
+ {
+ for (i = 0; i < nfds; i ++)
+ {
+# ifdef HAVE_POLL
+ DEBUG_printf(("pfds[%d].revents=%x\n", i, pfds[i].revents));
+ if (pfds[i].revents)
+# else
+ if (FD_ISSET(fds[i], &input))
+# endif /* HAVE_POLL */
+ {
+ *sock = fds[i];
+ len = sizeof(peer);
+ if (!getpeername(fds[i], (struct sockaddr *)&peer, &len))
+ {
+ DEBUG_printf(("1httpAddrConnect2: Connected to %s:%d...", httpAddrString(&peer, temp, sizeof(temp)), httpAddrPort(&peer)));
+
+ addrlist = addrs[i];
+ }
+ }
+ else
+ httpAddrClose(NULL, fds[i]);
+ }
+
+ return (addrlist);
+ }
+ }
+#endif /* O_NONBLOCK */
+
+ while (nfds > 0)
+ {
+ nfds --;
+ httpAddrClose(NULL, fds[nfds]);
+ }