mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-28 09:42:40 +01:00
refactor client connector waiters maintenance
This commit is contained in:
parent
e3dc6f0ca8
commit
cf38183dcb
@ -207,7 +207,7 @@ pub struct ClientConnector {
|
|||||||
acquired_per_host: HashMap<Key, usize>,
|
acquired_per_host: HashMap<Key, usize>,
|
||||||
available: HashMap<Key, VecDeque<Conn>>,
|
available: HashMap<Key, VecDeque<Conn>>,
|
||||||
to_close: Vec<Connection>,
|
to_close: Vec<Connection>,
|
||||||
waiters: HashMap<Key, VecDeque<Waiter>>,
|
waiters: Option<HashMap<Key, VecDeque<Waiter>>>,
|
||||||
wait_timeout: Option<(Instant, Delay)>,
|
wait_timeout: Option<(Instant, Delay)>,
|
||||||
paused: Paused,
|
paused: Paused,
|
||||||
}
|
}
|
||||||
@ -255,7 +255,7 @@ impl Default for ClientConnector {
|
|||||||
acquired_per_host: HashMap::new(),
|
acquired_per_host: HashMap::new(),
|
||||||
available: HashMap::new(),
|
available: HashMap::new(),
|
||||||
to_close: Vec::new(),
|
to_close: Vec::new(),
|
||||||
waiters: HashMap::new(),
|
waiters: Some(HashMap::new()),
|
||||||
wait_timeout: None,
|
wait_timeout: None,
|
||||||
paused: Paused::No,
|
paused: Paused::No,
|
||||||
}
|
}
|
||||||
@ -278,7 +278,7 @@ impl Default for ClientConnector {
|
|||||||
acquired_per_host: HashMap::new(),
|
acquired_per_host: HashMap::new(),
|
||||||
available: HashMap::new(),
|
available: HashMap::new(),
|
||||||
to_close: Vec::new(),
|
to_close: Vec::new(),
|
||||||
waiters: HashMap::new(),
|
waiters: Some(HashMap::new()),
|
||||||
wait_timeout: None,
|
wait_timeout: None,
|
||||||
paused: Paused::No,
|
paused: Paused::No,
|
||||||
}
|
}
|
||||||
@ -344,7 +344,7 @@ impl ClientConnector {
|
|||||||
acquired_per_host: HashMap::new(),
|
acquired_per_host: HashMap::new(),
|
||||||
available: HashMap::new(),
|
available: HashMap::new(),
|
||||||
to_close: Vec::new(),
|
to_close: Vec::new(),
|
||||||
waiters: HashMap::new(),
|
waiters: Some(HashMap::new()),
|
||||||
wait_timeout: None,
|
wait_timeout: None,
|
||||||
paused: Paused::No,
|
paused: Paused::No,
|
||||||
}
|
}
|
||||||
@ -504,7 +504,7 @@ impl ClientConnector {
|
|||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let mut next = None;
|
let mut next = None;
|
||||||
|
|
||||||
for waiters in self.waiters.values_mut() {
|
for waiters in self.waiters.as_mut().unwrap().values_mut() {
|
||||||
let mut idx = 0;
|
let mut idx = 0;
|
||||||
while idx < waiters.len() {
|
while idx < waiters.len() {
|
||||||
if waiters[idx].wait <= now {
|
if waiters[idx].wait <= now {
|
||||||
@ -556,6 +556,8 @@ impl ClientConnector {
|
|||||||
conn_timeout,
|
conn_timeout,
|
||||||
};
|
};
|
||||||
self.waiters
|
self.waiters
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
.entry(key)
|
.entry(key)
|
||||||
.or_insert_with(VecDeque::new)
|
.or_insert_with(VecDeque::new)
|
||||||
.push_back(waiter);
|
.push_back(waiter);
|
||||||
@ -835,9 +837,9 @@ impl fut::ActorFuture for Maintenance {
|
|||||||
act.collect_waiters();
|
act.collect_waiters();
|
||||||
|
|
||||||
// check waiters
|
// check waiters
|
||||||
let tmp: &mut ClientConnector = unsafe { &mut *(act as *mut _) };
|
let mut waiters = act.waiters.take().unwrap();
|
||||||
|
|
||||||
for (key, waiters) in &mut tmp.waiters {
|
for (key, waiters) in &mut waiters {
|
||||||
while let Some(waiter) = waiters.pop_front() {
|
while let Some(waiter) = waiters.pop_front() {
|
||||||
if waiter.tx.is_canceled() {
|
if waiter.tx.is_canceled() {
|
||||||
continue;
|
continue;
|
||||||
@ -865,7 +867,6 @@ impl fut::ActorFuture for Maintenance {
|
|||||||
),
|
),
|
||||||
).map_err(|_, _, _| ())
|
).map_err(|_, _, _| ())
|
||||||
.and_then(move |res, act, _| {
|
.and_then(move |res, act, _| {
|
||||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
|
||||||
#[cfg(feature = "alpn")]
|
#[cfg(feature = "alpn")]
|
||||||
match res {
|
match res {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@ -910,7 +911,6 @@ impl fut::ActorFuture for Maintenance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
|
||||||
#[cfg(all(feature = "tls", not(feature = "alpn")))]
|
#[cfg(all(feature = "tls", not(feature = "alpn")))]
|
||||||
match res {
|
match res {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@ -934,7 +934,8 @@ impl fut::ActorFuture for Maintenance {
|
|||||||
Ok(stream) => {
|
Ok(stream) => {
|
||||||
let _ = waiter.tx.send(
|
let _ = waiter.tx.send(
|
||||||
Ok(Connection::new(
|
Ok(Connection::new(
|
||||||
conn.0.clone(), Some(conn),
|
conn.0.clone(),
|
||||||
|
Some(conn),
|
||||||
Box::new(stream),
|
Box::new(stream),
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
@ -955,7 +956,6 @@ impl fut::ActorFuture for Maintenance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
|
||||||
#[cfg(not(any(feature = "alpn", feature = "tls")))]
|
#[cfg(not(any(feature = "alpn", feature = "tls")))]
|
||||||
match res {
|
match res {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@ -966,7 +966,9 @@ impl fut::ActorFuture for Maintenance {
|
|||||||
Ok(stream) => {
|
Ok(stream) => {
|
||||||
act.stats.opened += 1;
|
act.stats.opened += 1;
|
||||||
if conn.0.ssl {
|
if conn.0.ssl {
|
||||||
let _ = waiter.tx.send(Err(ClientConnectorError::SslIsNotSupported));
|
let _ = waiter.tx.send(Err(
|
||||||
|
ClientConnectorError::SslIsNotSupported,
|
||||||
|
));
|
||||||
} else {
|
} else {
|
||||||
let _ = waiter.tx.send(Ok(Connection::new(
|
let _ = waiter.tx.send(Ok(Connection::new(
|
||||||
conn.0.clone(),
|
conn.0.clone(),
|
||||||
@ -984,6 +986,7 @@ impl fut::ActorFuture for Maintenance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
act.waiters = Some(waiters);
|
||||||
Ok(Async::NotReady)
|
Ok(Async::NotReady)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user