From 29490e6c134d4165096808dbdc89e29f12143075 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 21 Aug 2018 21:11:16 -0700 Subject: [PATCH] cleanups --- .appveyor.yml | 2 +- .travis.yml | 6 +-- Cargo.toml | 14 ++---- examples/basic.rs | 3 ++ src/extensions.rs | 115 ---------------------------------------------- src/lib.rs | 88 ++--------------------------------- src/server.rs | 2 +- src/service.rs | 4 +- 8 files changed, 18 insertions(+), 216 deletions(-) delete mode 100644 src/extensions.rs diff --git a/.appveyor.yml b/.appveyor.yml index 7addc8c0..8b098353 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -37,4 +37,4 @@ build: false # Equivalent to Travis' `script` phase test_script: - - cargo test --no-default-features --features="flate2-rust" + - cargo test --no-default-features diff --git a/.travis.yml b/.travis.yml index f03c9523..ed218383 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,12 +32,12 @@ script: - | if [[ "$TRAVIS_RUST_VERSION" != "stable" ]]; then cargo clean - cargo test --features="alpn,tls,rust-tls" -- --nocapture + cargo test --features="ssl,tls,rust-tls" -- --nocapture fi - | if [[ "$TRAVIS_RUST_VERSION" == "stable" ]]; then RUSTFLAGS="--cfg procmacro2_semver_exempt" cargo install -f cargo-tarpaulin - cargo tarpaulin --features="alpn,tls,rust-tls" --out Xml --no-count + cargo tarpaulin --features="ssl,tls,rust-tls" --out Xml --no-count bash <(curl -s https://codecov.io/bash) echo "Uploaded code coverage" fi @@ -46,7 +46,7 @@ script: after_success: - | if [[ "$TRAVIS_OS_NAME" == "linux" && "$TRAVIS_PULL_REQUEST" = "false" && "$TRAVIS_BRANCH" == "master" && "$TRAVIS_RUST_VERSION" == "beta" ]]; then - cargo doc --features "alpn, tls, rust-tls, session" --no-deps && + cargo doc --features "ssl, tls, rust-tls, session" --no-deps && echo "" > target/doc/index.html && git clone https://github.com/davisp/ghp-import.git && ./ghp-import/ghp_import.py -n -p -f -m "Documentation upload" -r https://"$GH_TOKEN"@github.com/"$TRAVIS_REPO_SLUG.git" target/doc && diff --git a/Cargo.toml b/Cargo.toml index 5075711f..fc62d9de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,16 +2,13 @@ name = "actix-net" version = "0.1.0" authors = ["Nikolay Kim "] -description = "Actix net utils" +description = "Actix net - framework for the compisible network services for Rust" readme = "README.md" -keywords = ["http", "framework", "async", "futures"] +keywords = ["network", "framework", "async", "futures"] homepage = "https://actix.rs" repository = "https://github.com/actix/actix-net.git" documentation = "https://actix.rs/api/actix-net/stable/actix_web/" -categories = ["network-programming", "asynchronous", - "web-programming::http-server", - "web-programming::http-client", - "web-programming::websocket"] +categories = ["network-programming", "asynchronous"] license = "MIT/Apache-2.0" exclude = [".gitignore", ".travis.yml", ".cargo/config", "appveyor.yml"] @@ -44,19 +41,14 @@ actix = "0.7.0" log = "0.4" num_cpus = "1.0" -rand = "0.5" -time = "0.1" -parking_lot = "0.6" failure = "^0.1.2" # io mio = "^0.6.13" net2 = "0.2" bytes = "0.4" -byteorder = "1.2" futures = "0.1" slab = "0.4" -tokio = "0.1" tokio-io = "0.1" tokio-tcp = "0.1" tokio-timer = "0.2" diff --git a/examples/basic.rs b/examples/basic.rs index 1b60cdf3..001dcf28 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -83,6 +83,9 @@ fn main() { Ok::<_, io::Error>(ServiceState { num: num.clone() }) })); + // bind socket address and start workers. By default server uses number of + // available logical cpu as threads count. actix net start separate + // instances of service pipeline in each worker. Server::default().bind("0.0.0.0:8443", srv).unwrap().start(); sys.run(); diff --git a/src/extensions.rs b/src/extensions.rs deleted file mode 100644 index 35cd69db..00000000 --- a/src/extensions.rs +++ /dev/null @@ -1,115 +0,0 @@ -use std::any::{Any, TypeId}; -use std::collections::HashMap; -use std::fmt; -use std::hash::{BuildHasherDefault, Hasher}; - -struct IdHasher { - id: u64, -} - -impl Default for IdHasher { - fn default() -> IdHasher { - IdHasher { id: 0 } - } -} - -impl Hasher for IdHasher { - fn write(&mut self, bytes: &[u8]) { - for &x in bytes { - self.id.wrapping_add(u64::from(x)); - } - } - - fn write_u64(&mut self, u: u64) { - self.id = u; - } - - fn finish(&self) -> u64 { - self.id - } -} - -type AnyMap = HashMap, BuildHasherDefault>; - -/// A type map of request extensions. -#[derive(Default)] -pub struct Extensions { - map: AnyMap, -} - -impl Extensions { - /// Create an empty `Extensions`. - #[inline] - pub fn new() -> Extensions { - Extensions { - map: HashMap::default(), - } - } - - /// Insert a type into this `Extensions`. - /// - /// If a extension of this type already existed, it will - /// be returned. - pub fn insert(&mut self, val: T) { - self.map.insert(TypeId::of::(), Box::new(val)); - } - - /// Get a reference to a type previously inserted on this `Extensions`. - pub fn get(&self) -> Option<&T> { - self.map - .get(&TypeId::of::()) - .and_then(|boxed| (&**boxed as &(Any + 'static)).downcast_ref()) - } - - /// Get a mutable reference to a type previously inserted on this - /// `Extensions`. - pub fn get_mut(&mut self) -> Option<&mut T> { - self.map - .get_mut(&TypeId::of::()) - .and_then(|boxed| (&mut **boxed as &mut (Any + 'static)).downcast_mut()) - } - - /// Remove a type from this `Extensions`. - /// - /// If a extension of this type existed, it will be returned. - pub fn remove(&mut self) -> Option { - self.map.remove(&TypeId::of::()).and_then(|boxed| { - (boxed as Box) - .downcast() - .ok() - .map(|boxed| *boxed) - }) - } - - /// Clear the `Extensions` of all inserted extensions. - #[inline] - pub fn clear(&mut self) { - self.map.clear(); - } -} - -impl fmt::Debug for Extensions { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_struct("Extensions").finish() - } -} - -#[test] -fn test_extensions() { - #[derive(Debug, PartialEq)] - struct MyType(i32); - - let mut extensions = Extensions::new(); - - extensions.insert(5i32); - extensions.insert(MyType(10)); - - assert_eq!(extensions.get(), Some(&5i32)); - assert_eq!(extensions.get_mut(), Some(&mut 5i32)); - - assert_eq!(extensions.remove::(), Some(5i32)); - assert!(extensions.get::().is_none()); - - assert_eq!(extensions.get::(), None); - assert_eq!(extensions.get(), Some(&MyType(10))); -} diff --git a/src/lib.rs b/src/lib.rs index 9ef55abb..2aa42cf5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,35 +1,22 @@ -//! Actix web is a small, pragmatic, and extremely fast web framework -//! for Rust. +//! Actix net - framework for the compisible network services for Rust. //! //! ## Package feature //! //! * `tls` - enables ssl support via `native-tls` crate -//! * `alpn` - enables ssl support via `openssl` crate, require for `http/2` -//! support +//! * `ssl` - enables ssl support via `openssl` crate //! * `rust-tls` - enables ssl support via `rustls` crate //! - // #![warn(missing_docs)] -// #![allow( -// dead_code, -// unused_variables, -// unused_imports, -// patterns_in_fns_without_body -// )] #[macro_use] extern crate log; -extern crate byteorder; extern crate bytes; extern crate failure; extern crate futures; extern crate mio; extern crate net2; extern crate num_cpus; -extern crate parking_lot; extern crate slab; -extern crate time; -extern crate tokio; extern crate tokio_io; extern crate tokio_reactor; extern crate tokio_tcp; @@ -56,19 +43,12 @@ extern crate webpki; #[cfg(feature = "rust-tls")] extern crate webpki_roots; -use std::io; -use std::net::Shutdown; -use std::rc::Rc; - use actix::Message; -use bytes::{BufMut, BytesMut}; -use futures::{Async, Poll}; -use tokio_io::{AsyncRead, AsyncWrite}; +/// re-export for convinience. as a note, actix-net does not use `tower_service::NewService` trait. pub use tower_service::Service; pub(crate) mod accept; -mod extensions; mod server; pub mod server_config; mod server_service; @@ -76,12 +56,10 @@ pub mod service; pub mod ssl; mod worker; -pub use self::server::{ConnectionRateTag, ConnectionTag, Connections, Server}; +pub use server::Server; pub use server_config::Config; pub use service::{IntoNewService, IntoService, NewService}; -pub use extensions::Extensions; - /// Pause accepting incoming connections /// /// If socket contains some pending connection, they might be dropped. @@ -107,60 +85,4 @@ impl Message for StopServer { /// Socket id token #[derive(Clone, Copy)] -pub struct Token(usize); - -// impl Token { -// pub(crate) fn new(val: usize) -> Token { -// Token(val) -// } -// } - -const LW_BUFFER_SIZE: usize = 4096; -const HW_BUFFER_SIZE: usize = 32_768; - -#[doc(hidden)] -/// Low-level io stream operations -pub trait IoStream: AsyncRead + AsyncWrite + 'static { - fn shutdown(&mut self, how: Shutdown) -> io::Result<()>; - - fn set_nodelay(&mut self, nodelay: bool) -> io::Result<()>; - - fn set_linger(&mut self, dur: Option) -> io::Result<()>; - - fn read_available(&mut self, buf: &mut BytesMut) -> Poll { - let mut read_some = false; - loop { - if buf.remaining_mut() < LW_BUFFER_SIZE { - buf.reserve(HW_BUFFER_SIZE); - } - unsafe { - match self.read(buf.bytes_mut()) { - Ok(n) => { - if n == 0 { - return Ok(Async::Ready(!read_some)); - } else { - read_some = true; - buf.advance_mut(n); - } - } - Err(e) => { - return if e.kind() == io::ErrorKind::WouldBlock { - if read_some { - Ok(Async::Ready(false)) - } else { - Ok(Async::NotReady) - } - } else { - Err(e) - }; - } - } - } - } - } - - /// Extra io stream extensions - fn extensions(&self) -> Option> { - None - } -} +pub(crate) struct Token(usize); \ No newline at end of file diff --git a/src/server.rs b/src/server.rs index 6795471d..c3ba427a 100644 --- a/src/server.rs +++ b/src/server.rs @@ -70,7 +70,7 @@ impl Server { /// Set number of workers to start. /// - /// By default http server uses number of available logical cpu as threads + /// By default server uses number of available logical cpu as threads /// count. pub fn workers(mut self, num: usize) -> Self { self.threads = num; diff --git a/src/service.rs b/src/service.rs index e1440c6a..0cf5ca4d 100644 --- a/src/service.rs +++ b/src/service.rs @@ -207,7 +207,7 @@ where type InitError = IErr; type Future = FutureResult; - fn new_service(&self, cfg: Cfg) -> Self::Future { + fn new_service(&self, _: Cfg) -> Self::Future { future::ok(FnService::new(self.f.clone())) } } @@ -336,7 +336,7 @@ where type InitError = Err2; type Future = Box>; - fn new_service(&self, cfg: Cfg) -> Self::Future { + fn new_service(&self, _: Cfg) -> Self::Future { let f = self.f.clone(); Box::new( (self.state)()