OSDN Git Service

bionic: Sort and cache hosts file data for fast lookup
authorTom Marshall <tdm@cyngn.com>
Fri, 17 Jun 2016 23:38:12 +0000 (16:38 -0700)
committerSteve Kondik <steve@cyngn.com>
Sun, 4 Sep 2016 04:49:19 +0000 (21:49 -0700)
commit9ace2566af25a8ce2747e0a488e134a7c4f9f61d
tree585c27eb31d570dbee072590a48e1851e49199ef
parent1b00fdd5be81be1e0b27515bf6f31d228d59c231
bionic: Sort and cache hosts file data for fast lookup

The hosts file is normally searched linearly.  This is very slow when
the file is large.  To mitigate this, read the hosts file and sort the
entries in an in-memory cache.  When an address is requested via
gethostbyname or getaddrinfo, binary search the cache.

In case where the cache is not available, return a suitable error code
and fall back to the existing lookup code.

This has been written to behave as much like the existing lookup code as
possible.  But note bionic and glibc differ in behavior for some corner
cases.  Choose the most standard compliant behavior for these where
possible.  Otherwise choose the behavior that seems most reasonable.

Change-Id: I3b322883cbc48b0d76a0ce9d149b59faaac1dc58
libc/dns/net/getaddrinfo.c
libc/dns/net/hosts_cache.c [new file with mode: 0644]
libc/dns/net/hosts_cache.h [new file with mode: 0644]
libc/dns/net/sethostent.c