diff options
author | Tom Marshall <tdm@cyngn.com> | 2016-06-17 16:38:12 -0700 |
---|---|---|
committer | Gerrit Code Review <gerrit@cyanogenmod.org> | 2016-08-04 08:15:45 -0700 |
commit | 545862d54af2b210bba725cc655857f7d7068ad9 (patch) | |
tree | 83c7fca84541c27b6f532bff1cb179bc9e140dfe /libc/dns/net/hosts_cache.h | |
parent | 4e646507b980f2a1cd5dd8dee3e9e70e8880ce54 (diff) | |
download | bionic-545862d54af2b210bba725cc655857f7d7068ad9.zip bionic-545862d54af2b210bba725cc655857f7d7068ad9.tar.gz bionic-545862d54af2b210bba725cc655857f7d7068ad9.tar.bz2 |
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
Diffstat (limited to 'libc/dns/net/hosts_cache.h')
-rw-r--r-- | libc/dns/net/hosts_cache.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/libc/dns/net/hosts_cache.h b/libc/dns/net/hosts_cache.h new file mode 100644 index 0000000..fa5488f --- /dev/null +++ b/libc/dns/net/hosts_cache.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2016 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct getnamaddr; + +int hc_getaddrinfo(const char *host, const char *service, + const struct addrinfo *hints, + struct addrinfo **result); + +int hc_gethtbyname(const char *host, int af, struct getnamaddr *info); |