auto import from //branches/cupcake/...@132276

This commit is contained in:
The Android Open Source Project
2009-02-19 10:57:29 -08:00
parent 2489551343
commit 6f04a0f4c7
29 changed files with 1594 additions and 845 deletions

View File

@@ -626,37 +626,12 @@ gethostbyname_internal(const char *name, int af, res_state res)
break;
}
#ifdef ANDROID_CHANGES
cache = __get_res_cache();
if (cache != NULL) {
hp = _resolv_cache_lookup( cache, name, af );
if (hp == _RESOLV_HOSTENT_NONE) {
h_errno = HOST_NOT_FOUND;
return NULL;
}
if (hp != NULL) {
h_errno = NETDB_SUCCESS;
return hp;
}
}
#endif
hp = NULL;
h_errno = NETDB_INTERNAL;
if (nsdispatch(&hp, dtab, NSDB_HOSTS, "gethostbyname",
default_dns_files, name, strlen(name), af) != NS_SUCCESS) {
#ifdef ANDROID_CHANGES
/* cache negative DNS entry */
if (h_errno == HOST_NOT_FOUND && cache != NULL)
_resolv_cache_add( cache, name, af, _RESOLV_HOSTENT_NONE );
#endif
return NULL;
}
#ifdef ANDROID_CHANGES
if (cache != NULL) {
_resolv_cache_add( cache, name, af, hp );
}
#endif
h_errno = NETDB_SUCCESS;
return hp;
}

File diff suppressed because it is too large Load Diff

View File

@@ -81,6 +81,9 @@ __RCSID("$NetBSD: res_send.c,v 1.9 2006/01/24 17:41:25 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
/* set to 1 to use our small/simple/limited DNS cache */
#define USE_RESOLV_CACHE 1
/*
* Send query to name server and wait for reply.
*/
@@ -111,6 +114,10 @@ __RCSID("$NetBSD: res_send.c,v 1.9 2006/01/24 17:41:25 christos Exp $");
#include <isc/eventlib.h>
#if USE_RESOLV_CACHE
# include <resolv_cache.h>
#endif
#ifndef DE_CONST
#define DE_CONST(c,v) v = ((c) ? \
strchr((const void *)(c), *(const char *)(const void *)(c)) : NULL)
@@ -344,12 +351,17 @@ res_queriesmatch(const u_char *buf1, const u_char *eom1,
return (1);
}
int
res_nsend(res_state statp,
const u_char *buf, int buflen, u_char *ans, int anssiz)
{
int gotsomewhere, terrno, try, v_circuit, resplen, ns, n;
char abuf[NI_MAXHOST];
#if USE_RESOLV_CACHE
struct resolv_cache* cache;
ResolvCacheStatus cache_status = RESOLV_CACHE_UNSUPPORTED;
#endif
if (statp->nscount == 0) {
errno = ESRCH;
@@ -365,6 +377,20 @@ res_nsend(res_state statp,
gotsomewhere = 0;
terrno = ETIMEDOUT;
#if USE_RESOLV_CACHE
cache = __get_res_cache();
if (cache != NULL) {
int anslen = 0;
cache_status = _resolv_cache_lookup(
cache, buf, buflen,
ans, anssiz, &anslen);
if (cache_status == RESOLV_CACHE_FOUND) {
return anslen;
}
}
#endif
/*
* If the ns_addr_list in the resolver context has changed, then
* invalidate our cached copy and the associated timing data.
@@ -534,6 +560,12 @@ res_nsend(res_state statp,
(stdout, "%s", ""),
ans, (resplen > anssiz) ? anssiz : resplen);
#if USE_RESOLV_CACHE
if (cache_status == RESOLV_CACHE_NOTFOUND) {
_resolv_cache_add(cache, buf, buflen,
ans, resplen);
}
#endif
/*
* If we have temporarily opened a virtual circuit,
* or if we haven't been asked to keep a socket open,

View File

@@ -46,7 +46,6 @@ typedef struct {
struct __res_state _nres[1];
unsigned _serial;
struct prop_info* _pi;
struct hostent* _hostent;
struct res_static _rstatic[1];
} _res_thread;
@@ -66,9 +65,9 @@ _res_thread_alloc(void)
if ( res_ninit( rt->_nres ) < 0 ) {
free(rt);
rt = NULL;
} else {
memset(rt->_rstatic, 0, sizeof rt->_rstatic);
}
rt->_hostent = NULL;
memset(rt->_rstatic, 0, sizeof rt->_rstatic);
}
return rt;
}
@@ -93,7 +92,6 @@ _res_thread_free( void* _rt )
_res_thread* rt = _rt;
_res_static_done(rt->_rstatic);
_resolv_hostent_free(rt->_hostent);
res_ndestroy(rt->_nres);
free(rt);
}
@@ -132,6 +130,7 @@ _res_thread_get(void)
rt = NULL;
pthread_setspecific( _res_key, rt );
}
_resolv_cache_reset(rt->_serial);
return rt;
}
@@ -177,14 +176,6 @@ __res_put_state(res_state res)
res=res;
}
struct hostent**
__get_res_cache_hostent_p(void)
{
_res_thread* rt = _res_thread_get();
return rt ? &rt->_hostent : NULL;
}
res_static
__res_get_static(void)
{