diff options
author | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-24 06:31:34 +0000 |
---|---|---|
committer | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-24 06:31:34 +0000 |
commit | 025517044b4be3ab45efc2f383e5a7b830aa7281 (patch) | |
tree | b43566625f0702e8fa44590a7a82b3c41b56b5cc /net/base/host_resolver.cc | |
parent | 8943d1c09b155984790847a849e816ffe695a91a (diff) | |
download | chromium_src-025517044b4be3ab45efc2f383e5a7b830aa7281.zip chromium_src-025517044b4be3ab45efc2f383e5a7b830aa7281.tar.gz chromium_src-025517044b4be3ab45efc2f383e5a7b830aa7281.tar.bz2 |
Add support for mock DNS queries. This allows us to eliminate
flaky DNS queries from the unit tests.
Note: some unit tests still connect to www.google.com. My plan
is to resolve those in a subsequent CL.
R=wtc
BUG=2635
Review URL: http://codereview.chromium.org/4022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2545 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/host_resolver.cc')
-rw-r--r-- | net/base/host_resolver.cc | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/net/base/host_resolver.cc b/net/base/host_resolver.cc index ab706b3..d3b054f 100644 --- a/net/base/host_resolver.cc +++ b/net/base/host_resolver.cc @@ -26,8 +26,15 @@ namespace net { //----------------------------------------------------------------------------- -static int ResolveAddrInfo(const std::string& host, const std::string& port, - struct addrinfo** results) { +static HostMapper* host_mapper; + +HostMapper* SetHostMapper(HostMapper* value) { + std::swap(host_mapper, value); + return value; +} + +static int HostResolverProc( + const std::string& host, const std::string& port, struct addrinfo** out) { struct addrinfo hints = {0}; hints.ai_family = PF_UNSPEC; hints.ai_flags = AI_ADDRCONFIG; @@ -35,10 +42,21 @@ static int ResolveAddrInfo(const std::string& host, const std::string& port, // Restrict result set to only this socket type to avoid duplicates. hints.ai_socktype = SOCK_STREAM; - int err = getaddrinfo(host.c_str(), port.c_str(), &hints, results); + int err = getaddrinfo(host.c_str(), port.c_str(), &hints, out); return err ? ERR_NAME_NOT_RESOLVED : OK; } +static int ResolveAddrInfo( + const std::string& host, const std::string& port, struct addrinfo** out) { + int rv; + if (host_mapper) { + rv = HostResolverProc(host_mapper->Map(host), port, out); + } else { + rv = HostResolverProc(host, port, out); + } + return rv; +} + //----------------------------------------------------------------------------- class HostResolver::Request : |