- while (num && poll(pfd, num, -1) != -1) {
- for (i = 0; i < num; i++) {
- int err;
- socklen_t errlen = sizeof(err);
- if (!pfd[i].revents)
- continue;
- if (getsockopt(pfd[i].fd, SOL_SOCKET, SO_ERROR, &err,
- &errlen) != 0)
- goto out;
- if (err == 0)
- goto got_one;
-
- /* Remove dead one. */
- errno = err;
- remove_fd(pfd, addr, slen, &num, i--);
- }
+ /* Still going... */
+ errno = EINPROGRESS;
+ return -1;
+}
+
+int net_connect(const struct addrinfo *addrinfo)
+{
+ struct pollfd pfds[2];
+ int sockfd;
+
+ sockfd = net_connect_async(addrinfo, pfds);
+ /* Immediate connect or error is easy. */
+ if (sockfd >= 0 || errno != EINPROGRESS)
+ return sockfd;
+
+ while (poll(pfds, 2, -1) != -1) {
+ sockfd = net_connect_complete(pfds);
+ if (sockfd >= 0 || errno != EINPROGRESS)
+ return sockfd;