1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-24 07:02:59 +01:00

fix backpressure for ssl concurrent handshakes

This commit is contained in:
Nikolay Kim 2018-12-12 14:24:24 -08:00
parent 5ca00dc798
commit d1bfae7414
2 changed files with 9 additions and 7 deletions

View File

@ -9,6 +9,7 @@ use futures::task::AtomicTask;
/// Counter could be cloned, total ncount is shared across all clones. /// Counter could be cloned, total ncount is shared across all clones.
pub struct Counter(Rc<CounterInner>); pub struct Counter(Rc<CounterInner>);
#[derive(Debug)]
struct CounterInner { struct CounterInner {
count: Cell<usize>, count: Cell<usize>,
capacity: usize, capacity: usize,
@ -40,6 +41,7 @@ impl Counter {
} }
} }
#[derive(Debug)]
pub struct CounterGuard(Rc<CounterInner>); pub struct CounterGuard(Rc<CounterInner>);
impl CounterGuard { impl CounterGuard {
@ -57,11 +59,7 @@ impl Drop for CounterGuard {
impl CounterInner { impl CounterInner {
fn inc(&self) { fn inc(&self) {
let num = self.count.get() + 1; self.count.set(self.count.get() + 1);
self.count.set(num);
if num == self.capacity {
self.task.register();
}
} }
fn dec(&self) { fn dec(&self) {
@ -73,6 +71,10 @@ impl CounterInner {
} }
fn available(&self) -> bool { fn available(&self) -> bool {
self.count.get() < self.capacity let avail = self.count.get() < self.capacity;
if !avail {
self.task.register();
}
avail
} }
} }

View File

@ -398,7 +398,7 @@ impl Future for Worker {
let guard = self.conns.get(); let guard = self.conns.get();
let _ = self.services[msg.token.0] let _ = self.services[msg.token.0]
.as_mut() .as_mut()
.expect("actix net bug") .expect("actix-server bug")
.1 .1
.call((Some(guard), ServerMessage::Connect(msg.io))); .call((Some(guard), ServerMessage::Connect(msg.io)));
continue; continue;