+ if (sock >= 0)
+ {
+ fd_set rset, wset, eset;
+
+ FD_ZERO (&rset);
+ FD_SET (sock, &rset);
+ wset = rset;
+ eset = rset;
+
+ /* POSIX systems return connection success or failure by signalling
+ wset. Windows systems return success in wset and failure in
+ eset.
+
+ We must call select here, rather than gdb_select, because
+ the serial structure has not yet been initialized - the
+ MinGW select wrapper will not know that this FD refers
+ to a socket. */
+ n = select (sock + 1, &rset, &wset, &eset, &t);
+ }
+ else
+ /* Use gdb_select here, since we have no file descriptors, and on
+ Windows, plain select doesn't work in that case. */
+ n = interruptible_select (0, NULL, NULL, NULL, &t);
+
+ /* If we didn't time out, only count it as one poll. */
+ if (n > 0 || *polls < POLL_INTERVAL)
+ (*polls)++;
+ else
+ (*polls) += POLL_INTERVAL;
+
+ return n;
+}
+
+/* Try to connect to the host represented by AINFO. If the connection
+ succeeds, return its socket. Otherwise, return -1 and set ERRNO
+ accordingly. POLLS is used when 'connect' returns EINPROGRESS, and
+ we need to invoke 'wait_for_connect' to obtain the status. */
+
+static int
+try_connect (const struct addrinfo *ainfo, unsigned int *polls)
+{
+ int sock = gdb_socket_cloexec (ainfo->ai_family, ainfo->ai_socktype,
+ ainfo->ai_protocol);
+
+ if (sock < 0)
+ return -1;