mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-30 17:44:34 +01:00
use reusable box future in tls connector
This commit is contained in:
parent
7f0eddd794
commit
b5399c5631
@ -49,6 +49,7 @@ 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 }
|
||||
|
@ -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))),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user