1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-06-26 19:47:43 +02:00

clippy warnings

This commit is contained in:
Nikolay Kim
2019-12-02 22:30:09 +06:00
parent 9ed35cca7a
commit 9f575418c1
68 changed files with 355 additions and 452 deletions

View File

@ -1,9 +1,11 @@
# Changes
## [0.8.0-alpha.2] - 2019-11-xx
## [1.0.0-alpha.2] - 2019-12-02
### Changed
* Simplify server service (remove actix-server-config)
* Allow to wait on `Server` until server stops

View File

@ -1,6 +1,6 @@
[package]
name = "actix-server"
version = "0.8.0-alpha.2"
version = "1.0.0-alpha.2"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix server - General purpose tcp server"
keywords = ["network", "framework", "async", "futures"]
@ -21,9 +21,10 @@ path = "src/lib.rs"
default = []
[dependencies]
actix-service = "1.0.0-alpha.1"
actix-service = "1.0.0-alpha.2"
actix-rt = "1.0.0-alpha.2"
actix-codec = "0.2.0-alpha.1"
actix-codec = "0.2.0-alpha.2"
actix-utils = "1.0.0-alpha.2"
log = "0.4"
num_cpus = "1.0"
@ -40,5 +41,4 @@ mio-uds = { version = "0.6.7" }
[dev-dependencies]
bytes = "0.4"
actix-codec = "0.2.0-alpha.1"
env_logger = "0.6"

View File

@ -3,6 +3,7 @@ use std::{fmt, io, net};
use actix_rt::net::TcpStream;
use actix_service as actix;
use actix_utils::counter::CounterGuard;
use futures::future::{Future, FutureExt, LocalBoxFuture};
use log::error;
@ -11,7 +12,6 @@ use super::service::{
BoxedServerService, InternalServiceFactory, ServerMessage, StreamService,
};
use super::Token;
use crate::counter::CounterGuard;
pub struct ServiceConfig {
pub(crate) services: Vec<(String, net::TcpListener)>,
@ -126,9 +126,9 @@ impl InternalServiceFactory for ConfiguredService {
Ok(serv) => {
res.push((token, serv));
}
Err(e) => {
error!("Can not construct service {:?}", e);
return Err(e);
Err(_) => {
error!("Can not construct service");
return Err(());
}
};
}

View File

@ -1,81 +0,0 @@
use std::cell::Cell;
use std::rc::Rc;
use futures::task::AtomicWaker;
use std::task;
#[derive(Clone)]
/// Simple counter with ability to notify task on reaching specific number
///
/// 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,
task: AtomicWaker,
}
impl Counter {
/// Create `Counter` instance and set max value.
pub fn new(capacity: usize) -> Self {
Counter(Rc::new(CounterInner {
capacity,
count: Cell::new(0),
task: AtomicWaker::new(),
}))
}
pub fn get(&self) -> CounterGuard {
CounterGuard::new(self.0.clone())
}
/// Check if counter is not at capacity
pub fn available(&self, cx: &mut task::Context) -> bool {
self.0.available(cx)
}
/// Get total number of acquired counts
pub fn total(&self) -> usize {
self.0.count.get()
}
}
#[derive(Debug)]
pub struct CounterGuard(Rc<CounterInner>);
impl CounterGuard {
fn new(inner: Rc<CounterInner>) -> Self {
inner.inc();
CounterGuard(inner)
}
}
impl Drop for CounterGuard {
fn drop(&mut self) {
self.0.dec();
}
}
impl CounterInner {
fn inc(&self) {
self.count.set(self.count.get() + 1);
}
fn dec(&self) {
let num = self.count.get();
self.count.set(num - 1);
if num == self.capacity {
self.task.wake();
}
}
fn available(&self, cx: &mut task::Context) -> bool {
let avail = self.count.get() < self.capacity;
if !avail {
self.task.register(cx.waker());
}
avail
}
}

View File

@ -1,9 +1,10 @@
//! General purpose tcp server
#![deny(rust_2018_idioms, warnings)]
#![allow(clippy::type_complexity)]
mod accept;
mod builder;
mod config;
mod counter;
mod server;
mod service;
mod signals;

View File

@ -88,7 +88,7 @@ impl Clone for Server {
impl Future for Server {
type Output = io::Result<()>;
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.get_mut();
if this.1.is_none() {

View File

@ -5,12 +5,12 @@ use std::time::Duration;
use actix_rt::spawn;
use actix_service::{self as actix, Service, ServiceFactory as ActixServiceFactory};
use actix_utils::counter::CounterGuard;
use futures::future::{err, ok, LocalBoxFuture, Ready};
use futures::{FutureExt, TryFutureExt};
use log::error;
use super::Token;
use crate::counter::CounterGuard;
use crate::socket::{FromStream, StdStream};
/// Server message

View File

@ -50,10 +50,8 @@ impl Signals {
(unix::SignalKind::quit(), Signal::Quit),
];
for (kind, sig) in sig_map.into_iter() {
let sig = sig.clone();
let fut = unix::signal(*kind)?;
streams.push((sig, fut));
for (kind, sig) in sig_map.iter() {
streams.push((*sig, unix::signal(*kind)?));
}
Signals { srv, streams }

View File

@ -6,6 +6,7 @@ use std::{mem, time};
use actix_rt::time::{delay, Delay};
use actix_rt::{spawn, Arbiter};
use actix_utils::counter::Counter;
use futures::channel::mpsc::{UnboundedReceiver, UnboundedSender};
use futures::channel::oneshot;
use futures::future::{join_all, LocalBoxFuture, MapOk};
@ -13,7 +14,6 @@ use futures::{Future, FutureExt, Stream, TryFutureExt};
use log::{error, info, trace};
use crate::accept::AcceptNotify;
use crate::counter::Counter;
use crate::service::{BoxedServerService, InternalServiceFactory, ServerMessage};
use crate::socket::{SocketAddr, StdStream};
use crate::Token;
@ -332,11 +332,11 @@ impl Future for Worker {
}
}
self.availability.set(true);
return self.poll(cx);
self.poll(cx)
}
Ok(false) => {
self.state = WorkerState::Unavailable(conns);
return Poll::Pending;
Poll::Pending
}
Err((token, idx)) => {
trace!(
@ -345,7 +345,7 @@ impl Future for Worker {
);
self.state =
WorkerState::Restarting(idx, token, self.factories[idx].create());
return self.poll(cx);
self.poll(cx)
}
}
}
@ -372,7 +372,7 @@ impl Future for Worker {
return Poll::Pending;
}
}
return self.poll(cx);
self.poll(cx)
}
WorkerState::Shutdown(mut t1, mut t2, tx) => {
let num = num_connections();
@ -402,7 +402,7 @@ impl Future for Worker {
}
}
self.state = WorkerState::Shutdown(t1, t2, tx);
return Poll::Pending;
Poll::Pending
}
WorkerState::Available => {
loop {
@ -448,6 +448,6 @@ impl Future for Worker {
}
}
WorkerState::None => panic!(),
};
}
}
}