Skip to content

Commit

Permalink
back port bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Dec 13, 2018
1 parent c62567f commit 298727d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changes

## [0.2.5] - 2018-12-12

### Fixed

* Fix back-pressure for concurrent ssl handshakes

* Drop completed future for .then and .and_then combinators


## [0.2.4] - 2018-11-21

### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "actix-net"
version = "0.2.4"
version = "0.2.5"
authors = ["Nikolay Kim <[email protected]>"]
description = "Actix net - framework for the compisible network services for Rust (experimental)"
readme = "README.md"
Expand Down
14 changes: 8 additions & 6 deletions src/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use futures::task::AtomicTask;
/// Counter could be cloned, total ncount is shared across all clones.
pub struct Counter(Rc<CounterInner>);

#[derive(Debug)]
struct CounterInner {
count: Cell<usize>,
capacity: usize,
Expand Down Expand Up @@ -40,6 +41,7 @@ impl Counter {
}
}

#[derive(Debug)]
pub struct CounterGuard(Rc<CounterInner>);

impl CounterGuard {
Expand All @@ -57,11 +59,7 @@ impl Drop for CounterGuard {

impl CounterInner {
fn inc(&self) {
let num = self.count.get() + 1;
self.count.set(num);
if num == self.capacity {
self.task.register();
}
self.count.set(self.count.get() + 1);
}

fn dec(&self) {
Expand All @@ -73,6 +71,10 @@ impl CounterInner {
}

fn available(&self) -> bool {
self.count.get() < self.capacity
let avail = self.count.get() < self.capacity;
if !avail {
self.task.register();
}
avail
}
}
9 changes: 5 additions & 4 deletions src/service/and_then.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ where
{
b: Cell<B>,
fut_b: Option<B::Future>,
fut_a: A::Future,
fut_a: Option<A::Future>,
}

impl<A, B> AndThenFuture<A, B>
where
A: Service,
B: Service<Request = A::Response, Error = A::Error>,
{
fn new(fut_a: A::Future, b: Cell<B>) -> Self {
fn new(a: A::Future, b: Cell<B>) -> Self {
AndThenFuture {
b,
fut_a,
fut_a: Some(a),
fut_b: None,
}
}
Expand All @@ -94,8 +94,9 @@ where
return fut.poll();
}

match self.fut_a.poll() {
match self.fut_a.as_mut().expect("actix-net bug").poll() {
Ok(Async::Ready(resp)) => {
let _ = self.fut_a.take();
self.fut_b = Some(self.b.borrow_mut().call(resp));
self.poll()
}
Expand Down
10 changes: 6 additions & 4 deletions src/service/then.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ where
{
b: Cell<B>,
fut_b: Option<B::Future>,
fut_a: A::Future,
fut_a: Option<A::Future>,
}

impl<A, B> ThenFuture<A, B>
where
A: Service,
B: Service<Request = Result<A::Response, A::Error>>,
{
fn new(fut_a: A::Future, b: Cell<B>) -> Self {
fn new(a: A::Future, b: Cell<B>) -> Self {
ThenFuture {
b,
fut_a,
fut_a: Some(a),
fut_b: None,
}
}
Expand All @@ -93,12 +93,14 @@ where
return fut.poll();
}

match self.fut_a.poll() {
match self.fut_a.as_mut().expect("actix-net bug").poll() {
Ok(Async::Ready(resp)) => {
let _ = self.fut_a.take();
self.fut_b = Some(self.b.borrow_mut().call(Ok(resp)));
self.poll()
}
Err(err) => {
let _ = self.fut_a.take();
self.fut_b = Some(self.b.borrow_mut().call(Err(err)));
self.poll()
}
Expand Down

0 comments on commit 298727d

Please sign in to comment.