1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-30 17:44:34 +01:00

better method names

This commit is contained in:
Nikolay Kim 2018-09-14 13:12:55 -07:00
parent 39c3902818
commit 2927a49fdf
3 changed files with 13 additions and 11 deletions

View File

@ -11,15 +11,15 @@ pub struct Counter(Rc<CounterInner>);
struct CounterInner {
count: Cell<usize>,
max: usize,
capacity: usize,
task: AtomicTask,
}
impl Counter {
/// Create `Counter` instance and set max value.
pub fn new(max: usize) -> Self {
pub fn new(capacity: usize) -> Self {
Counter(Rc::new(CounterInner {
max,
capacity,
count: Cell::new(0),
task: AtomicTask::new(),
}))
@ -29,10 +29,12 @@ impl Counter {
CounterGuard::new(self.0.clone())
}
pub fn check(&self) -> bool {
self.0.check()
/// Check if counter is not at capacity
pub fn available(&self) -> bool {
self.0.available()
}
/// Get total number of acquired counts
pub fn total(&self) -> usize {
self.0.count.get()
}
@ -57,7 +59,7 @@ impl CounterInner {
fn inc(&self) {
let num = self.count.get() + 1;
self.count.set(num);
if num == self.max {
if num == self.capacity {
self.task.register();
}
}
@ -65,12 +67,12 @@ impl CounterInner {
fn dec(&self) {
let num = self.count.get();
self.count.set(num - 1);
if num == self.max {
if num == self.capacity {
self.task.notify();
}
}
fn check(&self) -> bool {
self.count.get() < self.max
fn available(&self) -> bool {
self.count.get() < self.capacity
}
}

View File

@ -169,7 +169,7 @@ impl Worker {
}
fn check_readiness(&mut self) -> Result<bool, usize> {
let mut ready = self.conns.check();
let mut ready = self.conns.available();
let mut failed = None;
for (idx, service) in self.services.iter_mut().enumerate() {
match service.poll_ready() {

View File

@ -69,7 +69,7 @@ impl<T: AsyncRead + AsyncWrite> Service for OpensslAcceptorService<T> {
type Future = OpensslAcceptorServiceFut<T>;
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
if self.conns.check() {
if self.conns.available() {
Ok(Async::Ready(()))
} else {
Ok(Async::NotReady)