Commit 483ff1ca authored by Yang Tse's avatar Yang Tse
Browse files

Constantine Sapuntzakis threaded resolver enhancements

parent c054b8bf
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -350,7 +350,8 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
#ifdef ENABLE_IPV6 /* CURLRES_IPV6 */
  struct in6_addr in6;
#endif /* CURLRES_IPV6 */
  *waitp = FALSE;

  *waitp = 0; /* default to synchronous response */

  /* First check if this is an IPv4 address string */
  if(Curl_inet_pton(AF_INET, hostname, &in) > 0) {
@@ -396,7 +397,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
    ares_gethostbyname(data->state.areschannel, hostname, family,
                       (ares_host_callback)ares_query_completed_cb, conn);

    *waitp = TRUE; /* please wait for the response */
    *waitp = 1; /* expect asynchronous response */
  }
  return NULL; /* no struct yet */
}
+6 −3
Original line number Diff line number Diff line
#ifndef __HOSTIP_H
#define __HOSTIP_H
#ifndef HEADER_CURL_HOSTIP_H
#define HEADER_CURL_HOSTIP_H
/***************************************************************************
 *                                  _   _ ____  _
 *  Project                     ___| | | |  _ \| |
@@ -165,6 +165,9 @@ int curl_dogetnameinfo(GETNAMEINFO_QUAL_ARG1 GETNAMEINFO_TYPE_ARG1 sa,
                       int line, const char *source);
#endif

/* IPv4 threadsafe resolve function used for synch and asynch builds */
Curl_addrinfo *Curl_ipv4_resolve_r(const char * hostname, int port);

/*
 * Curl_addrinfo_callback() is used when we build with any asynch specialty.
 * Handles end of async request processing. Inserts ai into hostcache when
@@ -214,4 +217,4 @@ void Curl_destroy_thread_data(struct Curl_async *async);
extern sigjmp_buf curl_jmpenv;
#endif

#endif
#endif /* HEADER_CURL_HOSTIP_H */
+48 −18
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
 * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution. The terms
@@ -87,8 +87,7 @@ bool Curl_ipvalid(struct SessionHandle *data)
  return TRUE; /* OK, proceed */
}

#ifdef CURLRES_SYNCH /* the functions below are for synchronous resolves */

#ifdef CURLRES_SYNCH
/*
 * Curl_getaddrinfo() - the ipv4 synchronous version.
 *
@@ -109,6 +108,33 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
                                const char *hostname,
                                int port,
                                int *waitp)
{
  Curl_addrinfo *ai = NULL;

#ifdef CURL_DISABLE_VERBOSE_STRINGS
  (void)conn;
#endif

  *waitp = 0; /* synchronous response only */

  ai = Curl_ipv4_resolve_r(hostname, port);
  if(!ai)
    infof(conn->data, "Curl_ipv4_resolve_r failed for %s\n", hostname);

  return ai;  
}
#endif /* CURLRES_SYNCH */
#endif /* CURLRES_IPV4 */

/*
 * Curl_ipv4_resolve_r() - ipv4 threadsafe resolver function.
 *
 * This is used for both synchronous and asynchronous resolver builds,
 * implying that only threadsafe code and function calls may be used.
 *
 */
Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname,
                                   int port)
{
#if defined(HAVE_GETHOSTBYNAME_R_3)
  int res;
@@ -118,17 +144,28 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
  struct in_addr in;
  struct hostent *buf = NULL;

#ifdef CURL_DISABLE_VERBOSE_STRINGS
  (void)conn;
#endif

  *waitp = 0; /* don't wait, we act synchronously */

  if(Curl_inet_pton(AF_INET, hostname, &in) > 0)
    /* This is a dotted IP address 123.123.123.123-style */
    return Curl_ip2addr(AF_INET, &in, hostname, port);

#if defined(HAVE_GETHOSTBYNAME_R)
#if defined(HAVE_GETADDRINFO_THREADSAFE)
  else { 
    struct addrinfo hints;
    char sbuf[NI_MAXSERV];
    char *sbufptr = NULL;
    int error;

    memset(&hints, 0, sizeof(hints));
    hints.ai_family = PF_INET;
    hints.ai_socktype = SOCK_STREAM;
    if (port) {
      snprintf(sbuf, sizeof(sbuf), "%d", port);
      sbufptr = sbuf;
    }
    hints.ai_flags = AI_CANONNAME;
    error = Curl_getaddrinfo_ex(hostname, sbufptr, &hints, &ai);

#elif defined(HAVE_GETHOSTBYNAME_R)
  /*
   * gethostbyname_r() is the preferred resolve function for many platforms.
   * Since there are three different versions of it, the following code is
@@ -261,7 +298,6 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
    else
#endif /* HAVE_GETHOSTBYNAME_R_3 */
    {
      infof(conn->data, "gethostbyname_r(2) failed for %s\n", hostname);
      h = NULL; /* set return code to NULL */
      free(buf);
    }
@@ -276,8 +312,6 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
#else
    h = gethostbyname(hostname);
#endif
    if(!h)
      infof(conn->data, "gethostbyname(2) failed for %s\n", hostname);
#endif /*HAVE_GETHOSTBYNAME_R */
  }

@@ -290,7 +324,3 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,

  return ai;
}

#endif /* CURLRES_SYNCH */
#endif /* CURLRES_IPV4 */
+3 −3
Original line number Diff line number Diff line
@@ -126,7 +126,7 @@ bool Curl_ipvalid(struct SessionHandle *data)
  return TRUE;
}

#if !defined(USE_THREADING_GETADDRINFO) && !defined(CURLRES_ARES)
#if defined(CURLRES_SYNCH)

#ifdef DEBUG_ADDRINFO
static void dump_addrinfo(struct connectdata *conn, const Curl_addrinfo *ai)
@@ -170,7 +170,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
  int pf;
  struct SessionHandle *data = conn->data;

  *waitp=0; /* don't wait, we have the response now */
  *waitp = 0; /* synchronous response only */

  /*
   * Check if a limited name resolve has been requested.
@@ -234,6 +234,6 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,

  return res;
}
#endif /* !USE_THREADING_GETADDRINFO && !CURLRES_ARES */
#endif /* CURLRES_SYNCH */
#endif /* CURLRES_IPV6 */
+224 −405

File changed.

Preview size limit exceeded, changes collapsed.