1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at http://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
22 ***************************************************************************/
28 #ifdef HAVE_SYS_SOCKET_H
29 #include <sys/socket.h>
31 #ifdef HAVE_NETINET_IN_H
32 #include <netinet/in.h>
37 #ifdef HAVE_ARPA_INET_H
38 #include <arpa/inet.h>
41 #include <stdlib.h> /* required for free() prototypes */
44 #include <unistd.h> /* for the close() proto */
64 #define _MPRINTF_REPLACE /* use our functions only */
65 #include <curl/mprintf.h>
67 #include "curl_memory.h"
68 /* The last #include file should be: */
71 /***********************************************************************
72 * Only for builds using asynchronous name resolves
73 **********************************************************************/
77 * Curl_addrinfo_callback() gets called by ares, gethostbyname_thread()
78 * or getaddrinfo_thread() when we got the name resolved (or not!).
80 * If the status argument is CURL_ASYNC_SUCCESS, this function takes
81 * ownership of the Curl_addrinfo passed, storing the resolved data
84 * The storage operation locks and unlocks the DNS cache.
86 CURLcode Curl_addrinfo_callback(struct connectdata * conn,
88 struct Curl_addrinfo *ai)
90 struct Curl_dns_entry *dns = NULL;
91 CURLcode rc = CURLE_OK;
93 conn->async.status = status;
95 if(CURL_ASYNC_SUCCESS == status) {
97 struct SessionHandle *data = conn->data;
100 Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE);
102 dns = Curl_cache_addr(data, ai,
103 conn->async.hostname,
106 /* failed to store, cleanup and return error */
107 Curl_freeaddrinfo(ai);
108 rc = CURLE_OUT_OF_MEMORY;
112 Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
115 rc = CURLE_OUT_OF_MEMORY;
118 conn->async.dns = dns;
120 /* Set async.done TRUE last in this function since it may be used multi-
121 threaded and once this is TRUE the other thread may read fields from the
123 conn->async.done = TRUE;
125 /* ipv4: The input hostent struct will be freed by ares when we return from
130 #endif /* CURLRES_ASYNCH */