mirror of
https://github.com/klzgrad/naiveproxy.git
synced 2024-11-24 14:26:09 +03:00
dns: Support Musl
This commit is contained in:
parent
4bc41bb0e5
commit
d7b841824c
@ -64,20 +64,32 @@ class DnsReloader : public NetworkChangeNotifier::DNSObserver {
|
|||||||
if (!reload_state) {
|
if (!reload_state) {
|
||||||
auto new_reload_state = std::make_unique<ReloadState>();
|
auto new_reload_state = std::make_unique<ReloadState>();
|
||||||
new_reload_state->resolver_generation = resolver_generation_;
|
new_reload_state->resolver_generation = resolver_generation_;
|
||||||
|
#ifdef __MUSL__
|
||||||
|
res_init();
|
||||||
|
#else
|
||||||
res_ninit(&_res);
|
res_ninit(&_res);
|
||||||
|
#endif
|
||||||
tls_reload_state_.Set(std::move(new_reload_state));
|
tls_reload_state_.Set(std::move(new_reload_state));
|
||||||
} else if (reload_state->resolver_generation != resolver_generation_) {
|
} else if (reload_state->resolver_generation != resolver_generation_) {
|
||||||
reload_state->resolver_generation = resolver_generation_;
|
reload_state->resolver_generation = resolver_generation_;
|
||||||
// It is safe to call res_nclose here since we know res_ninit will have
|
// It is safe to call res_nclose here since we know res_ninit will have
|
||||||
// been called above.
|
// been called above.
|
||||||
|
#ifdef __MUSL__
|
||||||
|
res_init();
|
||||||
|
#else
|
||||||
res_nclose(&_res);
|
res_nclose(&_res);
|
||||||
res_ninit(&_res);
|
res_ninit(&_res);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct ReloadState {
|
struct ReloadState {
|
||||||
~ReloadState() { res_nclose(&_res); }
|
~ReloadState() {
|
||||||
|
#ifndef __MUSL__
|
||||||
|
res_nclose(&_res);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int resolver_generation;
|
int resolver_generation;
|
||||||
};
|
};
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
namespace net {
|
namespace net {
|
||||||
|
|
||||||
ScopedResState::ScopedResState() {
|
ScopedResState::ScopedResState() {
|
||||||
#if BUILDFLAG(IS_OPENBSD) || BUILDFLAG(IS_FUCHSIA)
|
#if BUILDFLAG(IS_OPENBSD) || BUILDFLAG(IS_FUCHSIA) || defined(__MUSL__)
|
||||||
// Note: res_ninit in glibc always returns 0 and sets RES_INIT.
|
// Note: res_ninit in glibc always returns 0 and sets RES_INIT.
|
||||||
// res_init behaves the same way.
|
// res_init behaves the same way.
|
||||||
memset(&_res, 0, sizeof(_res));
|
memset(&_res, 0, sizeof(_res));
|
||||||
@ -25,7 +25,7 @@ ScopedResState::ScopedResState() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ScopedResState::~ScopedResState() {
|
ScopedResState::~ScopedResState() {
|
||||||
#if !BUILDFLAG(IS_OPENBSD) && !BUILDFLAG(IS_FUCHSIA)
|
#if !BUILDFLAG(IS_OPENBSD) && !BUILDFLAG(IS_FUCHSIA) && !defined(__MUSL__)
|
||||||
|
|
||||||
// Prefer res_ndestroy where available.
|
// Prefer res_ndestroy where available.
|
||||||
#if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_FREEBSD)
|
#if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_FREEBSD)
|
||||||
@ -43,7 +43,7 @@ bool ScopedResState::IsValid() const {
|
|||||||
|
|
||||||
const struct __res_state& ScopedResState::state() const {
|
const struct __res_state& ScopedResState::state() const {
|
||||||
DCHECK(IsValid());
|
DCHECK(IsValid());
|
||||||
#if BUILDFLAG(IS_OPENBSD) || BUILDFLAG(IS_FUCHSIA)
|
#if BUILDFLAG(IS_OPENBSD) || BUILDFLAG(IS_FUCHSIA) || defined(__MUSL__)
|
||||||
return _res;
|
return _res;
|
||||||
#else
|
#else
|
||||||
return res_;
|
return res_;
|
||||||
|
@ -31,7 +31,7 @@ class NET_EXPORT ScopedResState {
|
|||||||
virtual const struct __res_state& state() const;
|
virtual const struct __res_state& state() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#if !BUILDFLAG(IS_OPENBSD) && !BUILDFLAG(IS_FUCHSIA)
|
#if !BUILDFLAG(IS_OPENBSD) && !BUILDFLAG(IS_FUCHSIA) && !defined(__MUSL__)
|
||||||
struct __res_state res_;
|
struct __res_state res_;
|
||||||
#endif // !BUILDFLAG(IS_OPENBSD) && !BUILDFLAG(IS_FUCHSIA)
|
#endif // !BUILDFLAG(IS_OPENBSD) && !BUILDFLAG(IS_FUCHSIA)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user