mirror of
https://github.com/fafhrd91/actix-net
synced 2025-08-13 04:58:21 +02:00
Compare commits
10 Commits
rt-v2.0.0
...
utils-v3.0
Author | SHA1 | Date | |
---|---|---|---|
|
16ba77c4c8 | ||
|
b4a3f51659 | ||
|
9d0901e07f | ||
|
ebb9cd055f | ||
|
a77b70aed2 | ||
|
c918da906b | ||
|
b5399c5631 | ||
|
7f0eddd794 | ||
|
db3385e865 | ||
|
4a8693d000 |
@@ -17,7 +17,7 @@ quote = "1.0.3"
|
||||
syn = { version = "^1", features = ["full"] }
|
||||
|
||||
[dev-dependencies]
|
||||
actix-rt = "2.0.0-beta.3"
|
||||
actix-rt = "2.0.0"
|
||||
|
||||
futures-util = { version = "0.3", default-features = false }
|
||||
trybuild = "1"
|
||||
|
@@ -3,6 +3,12 @@
|
||||
## Unreleased - 2021-xx-xx
|
||||
|
||||
|
||||
## 2.0.1 - 2021-02-06
|
||||
* Expose `JoinError` from Tokio. [#271]
|
||||
|
||||
[#271]: https://github.com/actix/actix-net/pull/271
|
||||
|
||||
|
||||
## 2.0.0 - 2021-02-02
|
||||
* Remove all Arbiter-local storage methods. [#262]
|
||||
* Re-export `tokio::pin`. [#262]
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-rt"
|
||||
version = "2.0.0"
|
||||
version = "2.0.1"
|
||||
authors = [
|
||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||
"Rob Ede <robjtede@icloud.com>",
|
||||
@@ -26,8 +26,8 @@ macros = ["actix-macros"]
|
||||
actix-macros = { version = "0.2.0", optional = true }
|
||||
|
||||
futures-core = { version = "0.3", default-features = false }
|
||||
tokio = { version = "1", features = ["rt", "net", "parking_lot", "signal", "sync", "time"] }
|
||||
tokio = { version = "1.2", features = ["rt", "net", "parking_lot", "signal", "sync", "time"] }
|
||||
|
||||
[dev-dependencies]
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
tokio = { version = "1.2", features = ["full"] }
|
||||
hyper = { version = "0.14", default-features = false, features = ["server", "tcp", "http1"] }
|
||||
|
@@ -2,6 +2,4 @@
|
||||
|
||||
> Tokio-based single-threaded async runtime for the Actix ecosystem.
|
||||
|
||||
See documentation for detailed explanations these components: [https://docs.rs/actix-rt][docs].
|
||||
|
||||
[docs]: https://docs.rs/actix-rt
|
||||
See crate documentation for more: https://docs.rs/actix-rt.
|
||||
|
@@ -91,7 +91,7 @@ pub mod time {
|
||||
pub mod task {
|
||||
//! Task management (Tokio re-exports).
|
||||
|
||||
pub use tokio::task::{spawn_blocking, yield_now, JoinHandle};
|
||||
pub use tokio::task::{spawn_blocking, yield_now, JoinError, JoinHandle};
|
||||
}
|
||||
|
||||
/// Spawns a future on the current thread.
|
||||
|
@@ -1,9 +1,18 @@
|
||||
# Changes
|
||||
|
||||
## Unreleased - 2021-xx-xx
|
||||
|
||||
|
||||
## 2.0.0-beta.3 - 2021-02-06
|
||||
* Hidden `ServerBuilder::start` method has been removed. Use `ServerBuilder::run`. [#246]
|
||||
* Add retry for EINTR signal (`io::Interrupted`) in `Accept`'s poll loop. [#264]
|
||||
* Add `ServerBuilder::worker_max_blocking_threads` to customize blocking thread pool size. [#265]
|
||||
* Update `actix-rt` to `2.0.0`. [#273]
|
||||
|
||||
[#246]: https://github.com/actix/actix-net/pull/246
|
||||
[#264]: https://github.com/actix/actix-net/pull/264
|
||||
[#265]: https://github.com/actix/actix-net/pull/265
|
||||
[#273]: https://github.com/actix/actix-net/pull/273
|
||||
|
||||
|
||||
## 2.0.0-beta.2 - 2021-01-03
|
||||
|
@@ -25,8 +25,8 @@ default = []
|
||||
[dependencies]
|
||||
actix-codec = "0.4.0-beta.1"
|
||||
actix-rt = { version = "2.0.0", default-features = false }
|
||||
actix-service = "2.0.0-beta.3"
|
||||
actix-utils = "3.0.0-beta.1"
|
||||
actix-service = "2.0.0-beta.4"
|
||||
actix-utils = "3.0.0-beta.2"
|
||||
|
||||
futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] }
|
||||
log = "0.4"
|
||||
@@ -36,7 +36,7 @@ slab = "0.4"
|
||||
tokio = { version = "1", features = ["sync"] }
|
||||
|
||||
[dev-dependencies]
|
||||
actix-rt = "2.0.0-beta.2"
|
||||
actix-rt = "2.0.0"
|
||||
bytes = "1"
|
||||
env_logger = "0.8"
|
||||
futures-util = { version = "0.3.7", default-features = false, features = ["sink"] }
|
||||
|
@@ -161,9 +161,16 @@ impl Accept {
|
||||
let mut events = mio::Events::with_capacity(128);
|
||||
|
||||
loop {
|
||||
self.poll
|
||||
.poll(&mut events, None)
|
||||
.unwrap_or_else(|e| panic!("Poll error: {}", e));
|
||||
if let Err(e) = self.poll.poll(&mut events, None) {
|
||||
match e.kind() {
|
||||
std::io::ErrorKind::Interrupted => {
|
||||
continue;
|
||||
}
|
||||
_ => {
|
||||
panic!("Poll error: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for event in events.iter() {
|
||||
let token = event.token();
|
||||
|
@@ -19,7 +19,7 @@ use crate::signals::{Signal, Signals};
|
||||
use crate::socket::{MioListener, StdSocketAddr, StdTcpListener, ToSocketAddrs};
|
||||
use crate::socket::{MioTcpListener, MioTcpSocket};
|
||||
use crate::waker_queue::{WakerInterest, WakerQueue};
|
||||
use crate::worker::{self, ServerWorker, WorkerAvailability, WorkerHandle};
|
||||
use crate::worker::{self, ServerWorker, ServerWorkerConfig, WorkerAvailability, WorkerHandle};
|
||||
use crate::{join_all, Token};
|
||||
|
||||
/// Server builder
|
||||
@@ -32,11 +32,11 @@ pub struct ServerBuilder {
|
||||
sockets: Vec<(Token, String, MioListener)>,
|
||||
accept: AcceptLoop,
|
||||
exit: bool,
|
||||
shutdown_timeout: Duration,
|
||||
no_signals: bool,
|
||||
cmd: UnboundedReceiver<ServerCommand>,
|
||||
server: Server,
|
||||
notify: Vec<oneshot::Sender<()>>,
|
||||
worker_config: ServerWorkerConfig,
|
||||
}
|
||||
|
||||
impl Default for ServerBuilder {
|
||||
@@ -60,11 +60,11 @@ impl ServerBuilder {
|
||||
accept: AcceptLoop::new(server.clone()),
|
||||
backlog: 2048,
|
||||
exit: false,
|
||||
shutdown_timeout: Duration::from_secs(30),
|
||||
no_signals: false,
|
||||
cmd: rx,
|
||||
notify: Vec::new(),
|
||||
server,
|
||||
worker_config: ServerWorkerConfig::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,24 @@ impl ServerBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set max number of threads for each worker's blocking task thread pool.
|
||||
///
|
||||
/// One thread pool is set up **per worker**; not shared across workers.
|
||||
///
|
||||
/// # Examples:
|
||||
/// ```
|
||||
/// # use actix_server::ServerBuilder;
|
||||
/// let builder = ServerBuilder::new()
|
||||
/// .workers(4) // server has 4 worker thread.
|
||||
/// .worker_max_blocking_threads(4); // every worker has 4 max blocking threads.
|
||||
/// ```
|
||||
///
|
||||
/// See [tokio::runtime::Builder::max_blocking_threads] for behavior reference.
|
||||
pub fn worker_max_blocking_threads(mut self, num: usize) -> Self {
|
||||
self.worker_config.max_blocking_threads(num);
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the maximum number of pending connections.
|
||||
///
|
||||
/// This refers to the number of clients that can be waiting to be served.
|
||||
@@ -124,7 +142,8 @@ impl ServerBuilder {
|
||||
///
|
||||
/// By default shutdown timeout sets to 30 seconds.
|
||||
pub fn shutdown_timeout(mut self, sec: u64) -> Self {
|
||||
self.shutdown_timeout = Duration::from_secs(sec);
|
||||
self.worker_config
|
||||
.shutdown_timeout(Duration::from_secs(sec));
|
||||
self
|
||||
}
|
||||
|
||||
@@ -297,7 +316,7 @@ impl ServerBuilder {
|
||||
let avail = WorkerAvailability::new(waker);
|
||||
let services = self.services.iter().map(|v| v.clone_factory()).collect();
|
||||
|
||||
ServerWorker::start(idx, services, avail, self.shutdown_timeout)
|
||||
ServerWorker::start(idx, services, avail, self.worker_config)
|
||||
}
|
||||
|
||||
fn handle_cmd(&mut self, item: ServerCommand) {
|
||||
|
@@ -2,8 +2,6 @@ use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
|
||||
use crate::server::Server;
|
||||
|
||||
/// Different types of process signals
|
||||
@@ -23,9 +21,9 @@ pub(crate) enum Signal {
|
||||
pub(crate) struct Signals {
|
||||
srv: Server,
|
||||
#[cfg(not(unix))]
|
||||
signals: LocalBoxFuture<'static, std::io::Result<()>>,
|
||||
signals: futures_core::future::LocalBoxFuture<'static, std::io::Result<()>>,
|
||||
#[cfg(unix)]
|
||||
signals: Vec<(Signal, LocalBoxFuture<'static, ()>)>,
|
||||
signals: Vec<(Signal, actix_rt::signal::unix::Signal)>,
|
||||
}
|
||||
|
||||
impl Signals {
|
||||
@@ -48,23 +46,21 @@ impl Signals {
|
||||
(unix::SignalKind::quit(), Signal::Quit),
|
||||
];
|
||||
|
||||
let mut signals = Vec::new();
|
||||
|
||||
for (kind, sig) in sig_map.iter() {
|
||||
match unix::signal(*kind) {
|
||||
Ok(mut stream) => {
|
||||
let fut = Box::pin(async move {
|
||||
let _ = stream.recv().await;
|
||||
}) as _;
|
||||
signals.push((*sig, fut));
|
||||
}
|
||||
Err(e) => log::error!(
|
||||
"Can not initialize stream handler for {:?} err: {}",
|
||||
sig,
|
||||
e
|
||||
),
|
||||
}
|
||||
}
|
||||
let signals = sig_map
|
||||
.iter()
|
||||
.filter_map(|(kind, sig)| {
|
||||
unix::signal(*kind)
|
||||
.map(|tokio_sig| (*sig, tokio_sig))
|
||||
.map_err(|e| {
|
||||
log::error!(
|
||||
"Can not initialize stream handler for {:?} err: {}",
|
||||
sig,
|
||||
e
|
||||
)
|
||||
})
|
||||
.ok()
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
actix_rt::spawn(Signals { srv, signals });
|
||||
}
|
||||
@@ -86,7 +82,7 @@ impl Future for Signals {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
for (sig, fut) in self.signals.iter_mut() {
|
||||
if fut.as_mut().poll(cx).is_ready() {
|
||||
if Pin::new(fut).poll_recv(cx).is_ready() {
|
||||
let sig = *sig;
|
||||
self.srv.signal(sig);
|
||||
return Poll::Ready(());
|
||||
|
@@ -133,7 +133,7 @@ pub(crate) struct ServerWorker {
|
||||
conns: Counter,
|
||||
factories: Vec<Box<dyn InternalServiceFactory>>,
|
||||
state: WorkerState,
|
||||
shutdown_timeout: Duration,
|
||||
config: ServerWorkerConfig,
|
||||
}
|
||||
|
||||
struct WorkerService {
|
||||
@@ -159,26 +159,62 @@ enum WorkerServiceStatus {
|
||||
Stopped,
|
||||
}
|
||||
|
||||
/// Config for worker behavior passed down from server builder.
|
||||
#[derive(Copy, Clone)]
|
||||
pub(crate) struct ServerWorkerConfig {
|
||||
shutdown_timeout: Duration,
|
||||
max_blocking_threads: usize,
|
||||
}
|
||||
|
||||
impl Default for ServerWorkerConfig {
|
||||
fn default() -> Self {
|
||||
// 512 is the default max blocking thread count of tokio runtime.
|
||||
let max_blocking_threads = std::cmp::max(512 / num_cpus::get(), 1);
|
||||
Self {
|
||||
shutdown_timeout: Duration::from_secs(30),
|
||||
max_blocking_threads,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ServerWorkerConfig {
|
||||
pub(crate) fn max_blocking_threads(&mut self, num: usize) {
|
||||
self.max_blocking_threads = num;
|
||||
}
|
||||
|
||||
pub(crate) fn shutdown_timeout(&mut self, dur: Duration) {
|
||||
self.shutdown_timeout = dur;
|
||||
}
|
||||
}
|
||||
|
||||
impl ServerWorker {
|
||||
pub(crate) fn start(
|
||||
idx: usize,
|
||||
factories: Vec<Box<dyn InternalServiceFactory>>,
|
||||
availability: WorkerAvailability,
|
||||
shutdown_timeout: Duration,
|
||||
config: ServerWorkerConfig,
|
||||
) -> WorkerHandle {
|
||||
let (tx1, rx) = unbounded_channel();
|
||||
let (tx2, rx2) = unbounded_channel();
|
||||
let avail = availability.clone();
|
||||
|
||||
// every worker runs in it's own arbiter.
|
||||
Arbiter::new().spawn(Box::pin(async move {
|
||||
// use a custom tokio runtime builder to change the settings of runtime.
|
||||
Arbiter::with_tokio_rt(move || {
|
||||
tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.max_blocking_threads(config.max_blocking_threads)
|
||||
.build()
|
||||
.unwrap()
|
||||
})
|
||||
.spawn(async move {
|
||||
availability.set(false);
|
||||
let mut wrk = MAX_CONNS_COUNTER.with(move |conns| ServerWorker {
|
||||
rx,
|
||||
rx2,
|
||||
availability,
|
||||
factories,
|
||||
shutdown_timeout,
|
||||
config,
|
||||
services: Vec::new(),
|
||||
conns: conns.clone(),
|
||||
state: WorkerState::Unavailable,
|
||||
@@ -198,6 +234,8 @@ impl ServerWorker {
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// a second spawn to make sure worker future runs as non boxed future.
|
||||
// As Arbiter::spawn would box the future before send it to arbiter.
|
||||
spawn(async move {
|
||||
let res: Result<Vec<_>, _> = join_all(fut).await.into_iter().collect();
|
||||
match res {
|
||||
@@ -220,7 +258,7 @@ impl ServerWorker {
|
||||
}
|
||||
wrk.await
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
WorkerHandle::new(idx, tx1, tx2, avail)
|
||||
}
|
||||
@@ -324,7 +362,7 @@ impl Future for ServerWorker {
|
||||
info!("Graceful worker shutdown, {} connections", num);
|
||||
self.state = WorkerState::Shutdown(
|
||||
Box::pin(sleep_until(Instant::now() + Duration::from_secs(1))),
|
||||
Box::pin(sleep_until(Instant::now() + self.shutdown_timeout)),
|
||||
Box::pin(sleep_until(Instant::now() + self.config.shutdown_timeout)),
|
||||
Some(result),
|
||||
);
|
||||
} else {
|
||||
|
@@ -1,10 +1,13 @@
|
||||
# Changes
|
||||
|
||||
## Unreleased - 2021-xx-xx
|
||||
* `Service::poll_ready` and `Service::call` take `&self`. [#247]
|
||||
* `apply_fn` and `apply_fn_factory` would take `Fn(Req, &Service)` function type [#247]
|
||||
* `apply_cfg` and `apply_cfg_factory` would take `Fn(Req, &Service)` function type [#247]
|
||||
* `fn_service` module would take `Fn(Req)` function type. [#247]
|
||||
|
||||
|
||||
## 2.0.0-beta.4 - 2021-02-04
|
||||
* `Service::poll_ready` and `Service::call` receive `&self`. [#247]
|
||||
* `apply_fn` and `apply_fn_factory` now receive `Fn(Req, &Service)` function type. [#247]
|
||||
* `apply_cfg` and `apply_cfg_factory` now receive `Fn(Req, &Service)` function type. [#247]
|
||||
* `fn_service` and friends now receive `Fn(Req)` function type. [#247]
|
||||
|
||||
[#247]: https://github.com/actix/actix-net/pull/247
|
||||
|
||||
|
@@ -1,9 +1,10 @@
|
||||
[package]
|
||||
name = "actix-service"
|
||||
version = "2.0.0-beta.3"
|
||||
version = "2.0.0-beta.4"
|
||||
authors = [
|
||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||
"Rob Ede <robjtede@icloud.com>",
|
||||
"fakeshadow <24548779@qq.com>",
|
||||
]
|
||||
description = "Service trait and combinators for representing asynchronous request/response operations."
|
||||
keywords = ["network", "framework", "async", "futures", "service"]
|
||||
|
@@ -2,6 +2,12 @@
|
||||
|
||||
> Service trait and combinators for representing asynchronous request/response operations.
|
||||
|
||||
See documentation for detailed explanations these components: [https://docs.rs/actix-service][docs].
|
||||
[](https://crates.io/crates/actix-service)
|
||||
[](https://docs.rs/actix-service/2.0.0-beta.4)
|
||||
[](https://blog.rust-lang.org/2020/03/12/Rust-1.46.html)
|
||||

|
||||
[](https://deps.rs/crate/actix-service/2.0.0-beta.4)
|
||||
[](https://crates.io/crates/actix-service)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
[docs]: https://docs.rs/actix-service
|
||||
See documentation for detailed explanations of these components: https://docs.rs/actix-service.
|
||||
|
@@ -1,17 +1,22 @@
|
||||
# Changes
|
||||
|
||||
## Unreleased - 2021-xx-xx
|
||||
|
||||
|
||||
## 3.0.0-beta.3 - 2021-02-06
|
||||
* Remove `trust-dns-proto` and `trust-dns-resolver`. [#248]
|
||||
* Use `std::net::ToSocketAddrs` as simple and basic default resolver. [#248]
|
||||
* Add `Resolve` trait for custom dns resolver. [#248]
|
||||
* Add `Resolve` trait for custom DNS resolvers. [#248]
|
||||
* Add `Resolver::new_custom` function to construct custom resolvers. [#248]
|
||||
* Export `webpki_roots::TLS_SERVER_ROOTS` in `actix_tls::connect` mod and remove
|
||||
the export from `actix_tls::accept` [#248]
|
||||
* Remove `ConnectTakeAddrsIter`. `Connect::take_addrs` now returns `ConnectAddrsIter<'static>`
|
||||
as owned iterator. [#248]
|
||||
* Rename `Address::{host => hostname}` to more accurately describe which URL segment is returned.
|
||||
* Update `actix-rt` to `2.0.0`. [#273]
|
||||
|
||||
[#248]: https://github.com/actix/actix-net/pull/248
|
||||
[#273]: https://github.com/actix/actix-net/pull/273
|
||||
|
||||
|
||||
## 3.0.0-beta.2 - 2021-xx-xx
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-tls"
|
||||
version = "3.0.0-beta.2"
|
||||
version = "3.0.0-beta.3"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
description = "TLS acceptor and connector services for Actix ecosystem"
|
||||
keywords = ["network", "tls", "ssl", "async", "transport"]
|
||||
@@ -31,10 +31,10 @@ connect = []
|
||||
openssl = ["tls-openssl", "tokio-openssl"]
|
||||
|
||||
# use rustls impls
|
||||
rustls = ["tls-rustls", "webpki", "webpki-roots", "tokio-rustls"]
|
||||
rustls = ["tokio-rustls", "webpki-roots"]
|
||||
|
||||
# use native-tls impls
|
||||
native-tls = ["tls-native-tls", "tokio-native-tls"]
|
||||
native-tls = ["tokio-native-tls"]
|
||||
|
||||
# support http::Uri as connect address
|
||||
uri = ["http"]
|
||||
@@ -42,28 +42,24 @@ uri = ["http"]
|
||||
[dependencies]
|
||||
actix-codec = "0.4.0-beta.1"
|
||||
actix-rt = { version = "2.0.0", default-features = false }
|
||||
actix-service = "2.0.0-beta.3"
|
||||
actix-utils = "3.0.0-beta.1"
|
||||
actix-service = "2.0.0-beta.4"
|
||||
actix-utils = "3.0.0-beta.2"
|
||||
|
||||
derive_more = "0.99.5"
|
||||
futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] }
|
||||
http = { version = "0.2.3", optional = true }
|
||||
log = "0.4"
|
||||
tokio-util = { version = "0.6.3", default-features = false }
|
||||
|
||||
# openssl
|
||||
tls-openssl = { package = "openssl", version = "0.10", optional = true }
|
||||
tokio-openssl = { version = "0.6", optional = true }
|
||||
|
||||
# TODO: Reduce dependencies where tokio wrappers re-export base crate.
|
||||
|
||||
# rustls
|
||||
tls-rustls = { package = "rustls", version = "0.19", optional = true }
|
||||
tokio-rustls = { version = "0.22", optional = true }
|
||||
webpki = { version = "0.21", optional = true }
|
||||
webpki-roots = { version = "0.21", optional = true }
|
||||
|
||||
# native-tls
|
||||
tls-native-tls = { package = "native-tls", version = "0.2", optional = true }
|
||||
tokio-native-tls = { version = "0.3", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
|
@@ -15,9 +15,9 @@
|
||||
//! http --verify=false https://127.0.0.1:8443
|
||||
//! ```
|
||||
|
||||
// this rename only exists because of how we have organised the crate's feature flags
|
||||
// this use only exists because of how we have organised the crate
|
||||
// it is not necessary for your actual code
|
||||
extern crate tls_rustls as rustls;
|
||||
use tokio_rustls::rustls;
|
||||
|
||||
use std::{
|
||||
env,
|
||||
|
@@ -5,7 +5,7 @@ use actix_service::{Service, ServiceFactory};
|
||||
use actix_utils::counter::Counter;
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
|
||||
pub use native_tls::Error;
|
||||
pub use tokio_native_tls::native_tls::Error;
|
||||
pub use tokio_native_tls::{TlsAcceptor, TlsStream};
|
||||
|
||||
use super::MAX_CONN_COUNTER;
|
||||
|
@@ -12,7 +12,7 @@ use actix_utils::counter::{Counter, CounterGuard};
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
use tokio_rustls::{Accept, TlsAcceptor};
|
||||
|
||||
pub use rustls::{ServerConfig, Session};
|
||||
pub use tokio_rustls::rustls::{ServerConfig, Session};
|
||||
pub use tokio_rustls::server::TlsStream;
|
||||
|
||||
use super::MAX_CONN_COUNTER;
|
||||
|
@@ -11,6 +11,7 @@ use actix_rt::net::TcpStream;
|
||||
use actix_service::{Service, ServiceFactory};
|
||||
use futures_core::{future::LocalBoxFuture, ready};
|
||||
use log::{error, trace};
|
||||
use tokio_util::sync::ReusableBoxFuture;
|
||||
|
||||
use super::connect::{Address, Connect, ConnectAddrs, Connection};
|
||||
use super::error::ConnectError;
|
||||
@@ -65,7 +66,7 @@ pub enum TcpConnectorResponse<T> {
|
||||
req: Option<T>,
|
||||
port: u16,
|
||||
addrs: Option<VecDeque<SocketAddr>>,
|
||||
stream: Option<LocalBoxFuture<'static, Result<TcpStream, io::Error>>>,
|
||||
stream: Option<ReusableBoxFuture<Result<TcpStream, io::Error>>>,
|
||||
},
|
||||
Error(Option<ConnectError>),
|
||||
}
|
||||
@@ -90,7 +91,7 @@ impl<T: Address> TcpConnectorResponse<T> {
|
||||
req: Some(req),
|
||||
port,
|
||||
addrs: None,
|
||||
stream: Some(Box::pin(TcpStream::connect(addr))),
|
||||
stream: Some(ReusableBoxFuture::new(TcpStream::connect(addr))),
|
||||
},
|
||||
|
||||
// when resolver returns multiple socket addr for request they would be popped from
|
||||
@@ -119,7 +120,7 @@ impl<T: Address> Future for TcpConnectorResponse<T> {
|
||||
stream,
|
||||
} => loop {
|
||||
if let Some(new) = stream.as_mut() {
|
||||
match ready!(new.as_mut().poll(cx)) {
|
||||
match ready!(new.poll(cx)) {
|
||||
Ok(sock) => {
|
||||
let req = req.take().unwrap();
|
||||
trace!(
|
||||
@@ -146,7 +147,11 @@ impl<T: Address> Future for TcpConnectorResponse<T> {
|
||||
|
||||
// try to connect
|
||||
let addr = addrs.as_mut().unwrap().pop_front().unwrap();
|
||||
*stream = Some(Box::pin(TcpStream::connect(addr)));
|
||||
|
||||
match stream {
|
||||
Some(rbf) => rbf.set(TcpStream::connect(addr)),
|
||||
None => *stream = Some(ReusableBoxFuture::new(TcpStream::connect(addr))),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ use std::{
|
||||
task::{Context, Poll},
|
||||
};
|
||||
|
||||
pub use rustls::Session;
|
||||
pub use tokio_rustls::rustls::Session;
|
||||
pub use tokio_rustls::{client::TlsStream, rustls::ClientConfig};
|
||||
pub use webpki_roots::TLS_SERVER_ROOTS;
|
||||
|
||||
@@ -14,8 +14,8 @@ use actix_codec::{AsyncRead, AsyncWrite};
|
||||
use actix_service::{Service, ServiceFactory};
|
||||
use futures_core::{future::LocalBoxFuture, ready};
|
||||
use log::trace;
|
||||
use tokio_rustls::webpki::DNSNameRef;
|
||||
use tokio_rustls::{Connect, TlsConnector};
|
||||
use webpki::DNSNameRef;
|
||||
|
||||
use crate::connect::{Address, Connection};
|
||||
|
||||
|
@@ -4,12 +4,8 @@
|
||||
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
||||
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
||||
|
||||
#[cfg(feature = "native-tls")]
|
||||
extern crate tls_native_tls as native_tls;
|
||||
#[cfg(feature = "openssl")]
|
||||
extern crate tls_openssl as openssl;
|
||||
#[cfg(feature = "rustls")]
|
||||
extern crate tls_rustls as rustls;
|
||||
|
||||
#[cfg(feature = "accept")]
|
||||
pub mod accept;
|
||||
|
@@ -16,7 +16,7 @@ name = "actix_tracing"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
actix-service = "2.0.0-beta.3"
|
||||
actix-service = "2.0.0-beta.4"
|
||||
|
||||
futures-util = { version = "0.3.4", default-features = false }
|
||||
tracing = "0.1"
|
||||
|
@@ -3,6 +3,12 @@
|
||||
## Unreleased - 2021-xx-xx
|
||||
|
||||
|
||||
## 3.0.0-beta.2 - 2021-02-06
|
||||
* Update `actix-rt` to `2.0.0`. [#273]
|
||||
|
||||
[#273]: https://github.com/actix/actix-net/pull/273
|
||||
|
||||
|
||||
## 3.0.0-beta.1 - 2020-12-28
|
||||
* Update `bytes` dependency to `1`. [#237]
|
||||
* Use `pin-project-lite` to replace `pin-project`. [#229]
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-utils"
|
||||
version = "3.0.0-beta.1"
|
||||
version = "3.0.0-beta.2"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
description = "Various network related services and utilities for the Actix ecosystem"
|
||||
keywords = ["network", "framework", "async", "futures"]
|
||||
@@ -18,7 +18,7 @@ path = "src/lib.rs"
|
||||
[dependencies]
|
||||
actix-codec = "0.4.0-beta.1"
|
||||
actix-rt = { version = "2.0.0", default-features = false }
|
||||
actix-service = "2.0.0-beta.3"
|
||||
actix-service = "2.0.0-beta.4"
|
||||
|
||||
futures-core = { version = "0.3.7", default-features = false }
|
||||
futures-sink = { version = "0.3.7", default-features = false }
|
||||
@@ -26,4 +26,5 @@ log = "0.4"
|
||||
pin-project-lite = "0.2.0"
|
||||
|
||||
[dev-dependencies]
|
||||
actix-rt = "2.0.0"
|
||||
futures-util = { version = "0.3.7", default-features = false }
|
||||
|
@@ -24,4 +24,4 @@ serde = { version = "1.0", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json = "1.0"
|
||||
ahash = { version = "0.6", default-features = false }
|
||||
ahash = { version = "0.7", default-features = false }
|
||||
|
Reference in New Issue
Block a user