+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;
+ }
+
+ net_connect_abort(pfds);
+ return -1;