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. |
38 success_ = false; | 43 success_ = false; |
39 } | 44 } |
40 #if defined(OS_MACOSX) | 45 #if defined(OS_MACOSX) |
41 res_ndestroy(&res); | 46 res_ndestroy(&res); |
42 #else | 47 #elif !defined(OS_OPENBSD) |
43 res_nclose(&res); | 48 res_nclose(&res); |
44 #endif | 49 #endif |
wtc
2011/10/20 14:01:46
It may be better to apply #if defined(OS_OPENBSD)
Robert Nagy
2011/10/20 17:44:44
It is fine like this, but I extended the comment i
| |
45 } | 50 } |
46 | 51 |
47 void OnWorkFinished() OVERRIDE { | 52 void OnWorkFinished() OVERRIDE { |
48 DCHECK(!IsCancelled()); | 53 DCHECK(!IsCancelled()); |
49 if (success_) | 54 if (success_) |
50 service_->OnConfigRead(dns_config_); | 55 service_->OnConfigRead(dns_config_); |
51 } | 56 } |
52 | 57 |
53 private: | 58 private: |
54 virtual ~ConfigReader() {} | 59 virtual ~ConfigReader() {} |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 } | 121 } |
117 | 122 |
118 dns_config->search.clear(); | 123 dns_config->search.clear(); |
119 for (int i = 0; (i < MAXDNSRCH) && res.dnsrch[i]; ++i) { | 124 for (int i = 0; (i < MAXDNSRCH) && res.dnsrch[i]; ++i) { |
120 dns_config->search.push_back(std::string(res.dnsrch[i])); | 125 dns_config->search.push_back(std::string(res.dnsrch[i])); |
121 } | 126 } |
122 | 127 |
123 dns_config->ndots = res.ndots; | 128 dns_config->ndots = res.ndots; |
124 dns_config->timeout = base::TimeDelta::FromSeconds(res.retrans); | 129 dns_config->timeout = base::TimeDelta::FromSeconds(res.retrans); |
125 dns_config->attempts = res.retry; | 130 dns_config->attempts = res.retry; |
131 #if defined(RES_ROTATE) | |
126 dns_config->rotate = res.options & RES_ROTATE; | 132 dns_config->rotate = res.options & RES_ROTATE; |
133 #endif | |
127 dns_config->edns0 = res.options & RES_USE_EDNS0; | 134 dns_config->edns0 = res.options & RES_USE_EDNS0; |
128 | 135 |
129 return true; | 136 return true; |
130 } | 137 } |
131 | 138 |
132 } // namespace net | 139 } // namespace net |
OLD | NEW |