mirror of https://github.com/fafhrd91/actix-net
Merge branch 'master' into refactor/simplify_server_future
This commit is contained in:
commit
6b832b293c
|
@ -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"]
|
||||
|
@ -49,21 +49,17 @@ 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;
|
||||
|
||||
|
@ -15,7 +15,7 @@ use actix_service::{Service, ServiceFactory};
|
|||
use futures_core::{future::LocalBoxFuture, ready};
|
||||
use log::trace;
|
||||
use tokio_rustls::{Connect, TlsConnector};
|
||||
use webpki::DNSNameRef;
|
||||
use tokio_rustls::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;
|
||||
|
|
Loading…
Reference in New Issue