Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/base/host_resolver.h" | 5 #include "net/base/host_resolver.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <ws2tcpip.h> | 8 #include <ws2tcpip.h> |
| 9 #include <wspiapi.h> // Needed for Win2k compat. | 9 #include <wspiapi.h> // Needed for Win2k compat. |
| 10 #elif defined(OS_POSIX) | 10 #elif defined(OS_POSIX) |
| 11 #include <netdb.h> | 11 #include <netdb.h> |
| 12 #include <sys/socket.h> | 12 #include <sys/socket.h> |
| 13 #endif | 13 #endif |
| 14 #if defined(OS_LINUX) | |
| 15 #include <resolv.h> | |
| 16 #endif | |
| 14 | 17 |
| 15 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
| 16 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 17 #include "base/worker_pool.h" | 20 #include "base/worker_pool.h" |
| 18 #include "net/base/address_list.h" | 21 #include "net/base/address_list.h" |
| 19 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 20 | 23 |
| 21 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
| 22 #include "net/base/winsock_init.h" | 25 #include "net/base/winsock_init.h" |
| 23 #endif | 26 #endif |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 // See http://crbug.com/5234. | 68 // See http://crbug.com/5234. |
| 66 hints.ai_flags = 0; | 69 hints.ai_flags = 0; |
| 67 #else | 70 #else |
| 68 hints.ai_flags = AI_ADDRCONFIG; | 71 hints.ai_flags = AI_ADDRCONFIG; |
| 69 #endif | 72 #endif |
| 70 | 73 |
| 71 // Restrict result set to only this socket type to avoid duplicates. | 74 // Restrict result set to only this socket type to avoid duplicates. |
| 72 hints.ai_socktype = SOCK_STREAM; | 75 hints.ai_socktype = SOCK_STREAM; |
| 73 | 76 |
| 74 int err = getaddrinfo(host.c_str(), port.c_str(), &hints, out); | 77 int err = getaddrinfo(host.c_str(), port.c_str(), &hints, out); |
| 78 #if defined(OS_LINUX) | |
| 79 // If we fail, re-initialise the resolver just in case there have been any | |
| 80 // changes to /etc/resolv.conf and retry. See http://crbug.com/11380 for info. | |
| 81 if (err && !res_init()) | |
|
darin (slow to review)
2009/05/27 19:23:11
please use res_ninit instead, which is threadsafe.
| |
| 82 err = getaddrinfo(host.c_str(), port.c_str(), &hints, out); | |
| 83 #endif | |
| 84 | |
| 75 return err ? ERR_NAME_NOT_RESOLVED : OK; | 85 return err ? ERR_NAME_NOT_RESOLVED : OK; |
| 76 } | 86 } |
| 77 | 87 |
| 78 static int ResolveAddrInfo(HostMapper* mapper, const std::string& host, | 88 static int ResolveAddrInfo(HostMapper* mapper, const std::string& host, |
| 79 const std::string& port, struct addrinfo** out) { | 89 const std::string& port, struct addrinfo** out) { |
| 80 if (mapper) { | 90 if (mapper) { |
| 81 std::string mapped_host = mapper->Map(host); | 91 std::string mapped_host = mapper->Map(host); |
| 82 | 92 |
| 83 if (mapped_host.empty()) | 93 if (mapped_host.empty()) |
| 84 return ERR_NAME_NOT_RESOLVED; | 94 return ERR_NAME_NOT_RESOLVED; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 NewRunnableMethod(request_.get(), &Request::DoLookup), true)) { | 234 NewRunnableMethod(request_.get(), &Request::DoLookup), true)) { |
| 225 NOTREACHED(); | 235 NOTREACHED(); |
| 226 request_ = NULL; | 236 request_ = NULL; |
| 227 return ERR_FAILED; | 237 return ERR_FAILED; |
| 228 } | 238 } |
| 229 | 239 |
| 230 return ERR_IO_PENDING; | 240 return ERR_IO_PENDING; |
| 231 } | 241 } |
| 232 | 242 |
| 233 } // namespace net | 243 } // namespace net |
| OLD | NEW |