Commit 8952ef93 authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

Gisle's win32-fix. 'errno' is not used for errors when socket() fails on

Windows.
parent b350d5da
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -35,6 +35,12 @@
#include "ares_dns.h"
#include "ares_private.h"

#ifdef WIN32
#define GET_ERRNO()  WSAGetLastError()
#else
#define GET_ERRNO()  errno
#endif

static void write_tcp_data(ares_channel channel, fd_set *write_fds,
			   time_t now);
static void read_tcp_data(ares_channel channel, fd_set *read_fds, time_t now);
@@ -482,12 +488,14 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server)
  sockin.sin_family = AF_INET;
  sockin.sin_addr = server->addr;
  sockin.sin_port = channel->tcp_port;
  if (connect(s, (struct sockaddr *) &sockin, sizeof(sockin)) == -1
      && errno != EINPROGRESS)
    {
  if (connect(s, (struct sockaddr *) &sockin, sizeof(sockin)) == -1) {
    int err = GET_ERRNO();

    if (err != EINPROGRESS && err != EWOULDBLOCK) {
      closesocket(s);
      return -1;
    }
  }

  server->tcp_socket = s;
  return 0;