diff options
Diffstat (limited to 'Utilities/cmcurl/hostasyn.c')
-rw-r--r-- | Utilities/cmcurl/hostasyn.c | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/Utilities/cmcurl/hostasyn.c b/Utilities/cmcurl/hostasyn.c index b3c9dfa..3df1479 100644 --- a/Utilities/cmcurl/hostasyn.c +++ b/Utilities/cmcurl/hostasyn.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2006, 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 @@ -24,13 +24,10 @@ #include "setup.h" #include <string.h> -#include <errno.h> -#define _REENTRANT - -#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__) +#ifdef NEED_MALLOC_H #include <malloc.h> -#else +#endif #ifdef HAVE_SYS_TYPES_H #include <sys/types.h> #endif @@ -57,21 +54,15 @@ #include <inet.h> #include <stdlib.h> #endif -#endif #ifdef HAVE_SETJMP_H #include <setjmp.h> #endif -#ifdef WIN32 +#ifdef HAVE_PROCESS_H #include <process.h> #endif -#if (defined(NETWARE) && defined(__NOVELL_LIBC__)) -#undef in_addr_t -#define in_addr_t unsigned long -#endif - #include "urldata.h" #include "sendf.h" #include "hostip.h" @@ -87,7 +78,7 @@ #include "inet_ntoa_r.h" #endif -#include "curl_memory.h" +#include "memory.h" /* The last #include file should be: */ #include "memdebug.h" @@ -108,21 +99,21 @@ * * The storage operation locks and unlocks the DNS cache. */ -static void addrinfo_callback(void *arg, /* "struct connectdata *" */ - int status, - void *addr) +static CURLcode addrinfo_callback(void *arg, /* "struct connectdata *" */ + int status, + void *addr) { struct connectdata *conn = (struct connectdata *)arg; struct Curl_dns_entry *dns = NULL; + CURLcode rc = CURLE_OK; - conn->async.done = TRUE; conn->async.status = status; if(CURL_ASYNC_SUCCESS == status) { /* - * IPv4: Curl_addrinfo_copy() copies the address and returns an allocated - * version. + * IPv4/ares: Curl_addrinfo_copy() copies the address and returns an + * allocated version. * * IPv6: Curl_addrinfo_copy() returns the input pointer! */ @@ -136,34 +127,47 @@ static void addrinfo_callback(void *arg, /* "struct connectdata *" */ dns = Curl_cache_addr(data, ai, conn->async.hostname, conn->async.port); - if(!dns) + if(!dns) { /* failed to store, cleanup and return error */ Curl_freeaddrinfo(ai); + rc = CURLE_OUT_OF_MEMORY; + } if(data->share) Curl_share_unlock(data, CURL_LOCK_DATA_DNS); } + else + rc = CURLE_OUT_OF_MEMORY; } conn->async.dns = dns; + /* Set async.done TRUE last in this function since it may be used multi- + threaded and once this is TRUE the other thread may read fields from the + async struct */ + conn->async.done = TRUE; + /* ipv4: The input hostent struct will be freed by ares when we return from this function */ + return rc; } -void Curl_addrinfo4_callback(void *arg, /* "struct connectdata *" */ - int status, - struct hostent *hostent) +CURLcode Curl_addrinfo4_callback(void *arg, /* "struct connectdata *" */ + int status, + struct hostent *hostent) { - addrinfo_callback(arg, status, hostent); + return addrinfo_callback(arg, status, hostent); } #ifdef CURLRES_IPV6 -void Curl_addrinfo6_callback(void *arg, /* "struct connectdata *" */ - int status, - struct addrinfo *ai) +CURLcode Curl_addrinfo6_callback(void *arg, /* "struct connectdata *" */ + int status, + struct addrinfo *ai) { - addrinfo_callback(arg, status, ai); + /* NOTE: for CURLRES_ARES, the 'ai' argument is really a + * 'struct hostent' pointer. + */ + return addrinfo_callback(arg, status, ai); } #endif |