1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-01-19 08:24:41 +01:00

Use arbiters storage for default async resolver

This commit is contained in:
Nikolay Kim 2019-09-02 15:15:55 -07:00
parent 94e673b50b
commit b1d9b06a87
3 changed files with 13 additions and 13 deletions

View File

@ -1,5 +1,9 @@
# Changes
## [0.2.4] - 2019-09-02
* Use arbiter's storage for default async resolver
## [0.2.3] - 2019-08-05
* Add `ConnectService` and `OpensslConnectService`

View File

@ -1,6 +1,6 @@
[package]
name = "actix-connect"
version = "0.2.3"
version = "0.2.4"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix Connector - tcp connector service"
keywords = ["network", "framework", "async", "futures"]
@ -36,6 +36,7 @@ uri = ["http"]
actix-service = "0.4.0"
actix-codec = "0.1.2"
actix-utils = "0.4.0"
actix-rt = "0.2.5"
derive_more = "0.15"
either = "1.5.2"
futures = "0.1.25"

View File

@ -10,8 +10,6 @@
#[macro_use]
extern crate log;
use std::cell::RefCell;
mod connect;
mod connector;
mod error;
@ -32,6 +30,7 @@ pub use self::error::ConnectError;
pub use self::resolver::{Resolver, ResolverFactory};
pub use self::service::{ConnectService, ConnectServiceFactory};
use actix_rt::Arbiter;
use actix_service::{NewService, Service, ServiceExt};
use tokio_tcp::TcpStream;
@ -41,16 +40,12 @@ pub fn start_resolver(cfg: ResolverConfig, opts: ResolverOpts) -> AsyncResolver
resolver
}
thread_local! {
static DEFAULT_RESOLVER: RefCell<Option<AsyncResolver>> = RefCell::new(None);
}
struct DefaultResolver(AsyncResolver);
pub(crate) fn get_default_resolver() -> AsyncResolver {
DEFAULT_RESOLVER.with(|cell| {
if let Some(ref resolver) = *cell.borrow() {
return resolver.clone();
}
if Arbiter::contains_item::<DefaultResolver>() {
return Arbiter::get_item(|item: &DefaultResolver| item.0.clone());
} else {
let (cfg, opts) = match read_system_conf() {
Ok((cfg, opts)) => (cfg, opts),
Err(e) => {
@ -62,9 +57,9 @@ pub(crate) fn get_default_resolver() -> AsyncResolver {
let (resolver, bg) = AsyncResolver::new(cfg, opts);
tokio_current_thread::spawn(bg);
*cell.borrow_mut() = Some(resolver.clone());
Arbiter::set_item(DefaultResolver(resolver.clone()));
resolver
})
}
}
pub fn start_default_resolver() -> AsyncResolver {