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:
parent
94e673b50b
commit
b1d9b06a87
@ -1,5 +1,9 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.2.4] - 2019-09-02
|
||||||
|
|
||||||
|
* Use arbiter's storage for default async resolver
|
||||||
|
|
||||||
## [0.2.3] - 2019-08-05
|
## [0.2.3] - 2019-08-05
|
||||||
|
|
||||||
* Add `ConnectService` and `OpensslConnectService`
|
* Add `ConnectService` and `OpensslConnectService`
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-connect"
|
name = "actix-connect"
|
||||||
version = "0.2.3"
|
version = "0.2.4"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix Connector - tcp connector service"
|
description = "Actix Connector - tcp connector service"
|
||||||
keywords = ["network", "framework", "async", "futures"]
|
keywords = ["network", "framework", "async", "futures"]
|
||||||
@ -36,6 +36,7 @@ uri = ["http"]
|
|||||||
actix-service = "0.4.0"
|
actix-service = "0.4.0"
|
||||||
actix-codec = "0.1.2"
|
actix-codec = "0.1.2"
|
||||||
actix-utils = "0.4.0"
|
actix-utils = "0.4.0"
|
||||||
|
actix-rt = "0.2.5"
|
||||||
derive_more = "0.15"
|
derive_more = "0.15"
|
||||||
either = "1.5.2"
|
either = "1.5.2"
|
||||||
futures = "0.1.25"
|
futures = "0.1.25"
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
|
||||||
|
|
||||||
mod connect;
|
mod connect;
|
||||||
mod connector;
|
mod connector;
|
||||||
mod error;
|
mod error;
|
||||||
@ -32,6 +30,7 @@ pub use self::error::ConnectError;
|
|||||||
pub use self::resolver::{Resolver, ResolverFactory};
|
pub use self::resolver::{Resolver, ResolverFactory};
|
||||||
pub use self::service::{ConnectService, ConnectServiceFactory};
|
pub use self::service::{ConnectService, ConnectServiceFactory};
|
||||||
|
|
||||||
|
use actix_rt::Arbiter;
|
||||||
use actix_service::{NewService, Service, ServiceExt};
|
use actix_service::{NewService, Service, ServiceExt};
|
||||||
use tokio_tcp::TcpStream;
|
use tokio_tcp::TcpStream;
|
||||||
|
|
||||||
@ -41,16 +40,12 @@ pub fn start_resolver(cfg: ResolverConfig, opts: ResolverOpts) -> AsyncResolver
|
|||||||
resolver
|
resolver
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_local! {
|
struct DefaultResolver(AsyncResolver);
|
||||||
static DEFAULT_RESOLVER: RefCell<Option<AsyncResolver>> = RefCell::new(None);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_default_resolver() -> AsyncResolver {
|
pub(crate) fn get_default_resolver() -> AsyncResolver {
|
||||||
DEFAULT_RESOLVER.with(|cell| {
|
if Arbiter::contains_item::<DefaultResolver>() {
|
||||||
if let Some(ref resolver) = *cell.borrow() {
|
return Arbiter::get_item(|item: &DefaultResolver| item.0.clone());
|
||||||
return resolver.clone();
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
let (cfg, opts) = match read_system_conf() {
|
let (cfg, opts) = match read_system_conf() {
|
||||||
Ok((cfg, opts)) => (cfg, opts),
|
Ok((cfg, opts)) => (cfg, opts),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@ -62,9 +57,9 @@ pub(crate) fn get_default_resolver() -> AsyncResolver {
|
|||||||
let (resolver, bg) = AsyncResolver::new(cfg, opts);
|
let (resolver, bg) = AsyncResolver::new(cfg, opts);
|
||||||
tokio_current_thread::spawn(bg);
|
tokio_current_thread::spawn(bg);
|
||||||
|
|
||||||
*cell.borrow_mut() = Some(resolver.clone());
|
Arbiter::set_item(DefaultResolver(resolver.clone()));
|
||||||
resolver
|
resolver
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_default_resolver() -> AsyncResolver {
|
pub fn start_default_resolver() -> AsyncResolver {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user