summaryrefslogtreecommitdiff
path: root/ares_gethostbyname.c
diff options
context:
space:
mode:
authorSteinar H. Gunderson <sesse@google.com>2007-09-28 14:46:51 +0000
committerSteinar H. Gunderson <sesse@google.com>2007-09-28 14:46:51 +0000
commit50ba81cd230f9054fa7c45cb4202ce8720c502b3 (patch)
tree277c02b995aacc09540ec58270e10cd1845ff2b3 /ares_gethostbyname.c
parentb669e17544c0ff64d120b8a0df2677c59ccea8fd (diff)
downloadc-ares-50ba81cd230f9054fa7c45cb4202ce8720c502b3.tar.gz
c-ares-50ba81cd230f9054fa7c45cb4202ce8720c502b3.tar.bz2
c-ares-50ba81cd230f9054fa7c45cb4202ce8720c502b3.zip
Make the query callbacks return the number of timeouts that happened during the execution of a query, and update documentation accordingly. (Patch from the Google tree.)
Diffstat (limited to 'ares_gethostbyname.c')
-rw-r--r--ares_gethostbyname.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/ares_gethostbyname.c b/ares_gethostbyname.c
index c0fa474..49ae53e 100644
--- a/ares_gethostbyname.c
+++ b/ares_gethostbyname.c
@@ -54,11 +54,12 @@ struct host_query {
void *arg;
int family;
const char *remaining_lookups;
+ int timeouts;
};
static void next_lookup(struct host_query *hquery);
-static void host_callback(void *arg, int status, unsigned char *abuf,
- int alen);
+static void host_callback(void *arg, int status, int timeouts,
+ unsigned char *abuf, int alen);
static void end_hquery(struct host_query *hquery, int status,
struct hostent *host);
static int fake_hostent(const char *name, int family, ares_host_callback callback,
@@ -81,7 +82,7 @@ void ares_gethostbyname(ares_channel channel, const char *name, int family,
/* Right now we only know how to look up Internet addresses. */
if (family != AF_INET && family != AF_INET6)
{
- callback(arg, ARES_ENOTIMP, NULL);
+ callback(arg, ARES_ENOTIMP, 0, NULL);
return;
}
@@ -92,7 +93,7 @@ void ares_gethostbyname(ares_channel channel, const char *name, int family,
hquery = malloc(sizeof(struct host_query));
if (!hquery)
{
- callback(arg, ARES_ENOMEM, NULL);
+ callback(arg, ARES_ENOMEM, 0, NULL);
return;
}
hquery->channel = channel;
@@ -101,12 +102,13 @@ void ares_gethostbyname(ares_channel channel, const char *name, int family,
if (!hquery->name)
{
free(hquery);
- callback(arg, ARES_ENOMEM, NULL);
+ callback(arg, ARES_ENOMEM, 0, NULL);
return;
}
hquery->callback = callback;
hquery->arg = arg;
hquery->remaining_lookups = channel->lookups;
+ hquery->timeouts = 0;
/* Start performing lookups according to channel->lookups. */
next_lookup(hquery);
@@ -144,15 +146,16 @@ static void next_lookup(struct host_query *hquery)
break;
}
}
- end_hquery(hquery, ARES_ENOTFOUND, NULL);
}
-static void host_callback(void *arg, int status, unsigned char *abuf, int alen)
+static void host_callback(void *arg, int status, int timeouts,
+ unsigned char *abuf, int alen)
{
struct host_query *hquery = (struct host_query *) arg;
ares_channel channel = hquery->channel;
struct hostent *host;
+ hquery->timeouts += timeouts;
if (status == ARES_SUCCESS)
{
if (hquery->family == AF_INET)
@@ -185,7 +188,7 @@ static void host_callback(void *arg, int status, unsigned char *abuf, int alen)
static void end_hquery(struct host_query *hquery, int status,
struct hostent *host)
{
- hquery->callback(hquery->arg, status, host);
+ hquery->callback(hquery->arg, status, hquery->timeouts, host);
if (host)
ares_free_hostent(host);
free(hquery->name);
@@ -227,7 +230,7 @@ static int fake_hostent(const char *name, int family, ares_host_callback callbac
hostent.h_name = strdup(name);
if (!hostent.h_name)
{
- callback(arg, ARES_ENOMEM, NULL);
+ callback(arg, ARES_ENOMEM, 0, NULL);
return 1;
}
@@ -236,7 +239,7 @@ static int fake_hostent(const char *name, int family, ares_host_callback callbac
hostent.h_aliases = aliases;
hostent.h_addrtype = family;
hostent.h_addr_list = addrs;
- callback(arg, ARES_SUCCESS, &hostent);
+ callback(arg, ARES_SUCCESS, 0, &hostent);
free((char *)(hostent.h_name));
return 1;
@@ -416,4 +419,3 @@ static int get6_address_index(struct in6_addr *addr, struct apattern *sortlist,
}
return i;
}
-