| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/dns/dns_config_service_posix.h" | 5 #include "net/dns/dns_config_service_posix.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 // A SerialWorker that uses ResolverLib to initialize res_state and converts | 24 // A SerialWorker that uses ResolverLib to initialize res_state and converts |
| 25 // it to DnsConfig. | 25 // it to DnsConfig. |
| 26 class DnsConfigServicePosix::ConfigReader : public SerialWorker { | 26 class DnsConfigServicePosix::ConfigReader : public SerialWorker { |
| 27 public: | 27 public: |
| 28 explicit ConfigReader(DnsConfigServicePosix* service) | 28 explicit ConfigReader(DnsConfigServicePosix* service) |
| 29 : service_(service), | 29 : service_(service), |
| 30 success_(false) {} | 30 success_(false) {} |
| 31 | 31 |
| 32 void DoWork() OVERRIDE { | 32 void DoWork() OVERRIDE { |
| 33 #if defined(OS_OPENBSD) |
| 34 if ((res_init() == 0) && (_res.options & RES_INIT)) { |
| 35 success_ = ConvertResToConfig(_res, &dns_config_); |
| 36 #else |
| 33 struct __res_state res; | 37 struct __res_state res; |
| 34 if ((res_ninit(&res) == 0) && (res.options & RES_INIT)) { | 38 if ((res_ninit(&res) == 0) && (res.options & RES_INIT)) { |
| 35 success_ = ConvertResToConfig(res, &dns_config_); | 39 success_ = ConvertResToConfig(res, &dns_config_); |
| 40 #endif |
| 36 } else { | 41 } else { |
| 37 // Note: res_ninit in glibc always returns 0 and sets RES_INIT. | 42 // Note: res_ninit in glibc always returns 0 and sets RES_INIT. |
| 43 // res_init behaves the same way. |
| 38 success_ = false; | 44 success_ = false; |
| 39 } | 45 } |
| 40 #if defined(OS_MACOSX) | 46 #if defined(OS_MACOSX) |
| 41 res_ndestroy(&res); | 47 res_ndestroy(&res); |
| 42 #else | 48 #elif !defined(OS_OPENBSD) |
| 43 res_nclose(&res); | 49 res_nclose(&res); |
| 44 #endif | 50 #endif |
| 45 } | 51 } |
| 46 | 52 |
| 47 void OnWorkFinished() OVERRIDE { | 53 void OnWorkFinished() OVERRIDE { |
| 48 DCHECK(!IsCancelled()); | 54 DCHECK(!IsCancelled()); |
| 49 if (success_) | 55 if (success_) |
| 50 service_->OnConfigRead(dns_config_); | 56 service_->OnConfigRead(dns_config_); |
| 51 } | 57 } |
| 52 | 58 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 122 } |
| 117 | 123 |
| 118 dns_config->search.clear(); | 124 dns_config->search.clear(); |
| 119 for (int i = 0; (i < MAXDNSRCH) && res.dnsrch[i]; ++i) { | 125 for (int i = 0; (i < MAXDNSRCH) && res.dnsrch[i]; ++i) { |
| 120 dns_config->search.push_back(std::string(res.dnsrch[i])); | 126 dns_config->search.push_back(std::string(res.dnsrch[i])); |
| 121 } | 127 } |
| 122 | 128 |
| 123 dns_config->ndots = res.ndots; | 129 dns_config->ndots = res.ndots; |
| 124 dns_config->timeout = base::TimeDelta::FromSeconds(res.retrans); | 130 dns_config->timeout = base::TimeDelta::FromSeconds(res.retrans); |
| 125 dns_config->attempts = res.retry; | 131 dns_config->attempts = res.retry; |
| 132 #if defined(RES_ROTATE) |
| 126 dns_config->rotate = res.options & RES_ROTATE; | 133 dns_config->rotate = res.options & RES_ROTATE; |
| 134 #endif |
| 127 dns_config->edns0 = res.options & RES_USE_EDNS0; | 135 dns_config->edns0 = res.options & RES_USE_EDNS0; |
| 128 | 136 |
| 129 return true; | 137 return true; |
| 130 } | 138 } |
| 131 | 139 |
| 132 } // namespace net | 140 } // namespace net |
| OLD | NEW |