From a4d47704623dcba961f3be456a3c0f6b4e1f19ff Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Fri, 8 Mar 2019 22:38:39 -0800 Subject: [PATCH] remove server config --- Cargo.toml | 1 - actix-server-config/Cargo.toml | 18 ----------------- actix-server-config/src/lib.rs | 33 ------------------------------- actix-server/Cargo.toml | 1 - actix-server/src/builder.rs | 14 ++++++------- actix-server/src/lib.rs | 2 -- actix-server/src/services.rs | 26 ++++++------------------ actix-server/tests/test_server.rs | 18 ++++------------- 8 files changed, 16 insertions(+), 97 deletions(-) delete mode 100644 actix-server-config/Cargo.toml delete mode 100644 actix-server-config/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 973b2f2f..88a87427 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,6 @@ members = [ "actix-rt", "actix-service", "actix-server", - "actix-server-config", "actix-test-server", "actix-utils", "router", diff --git a/actix-server-config/Cargo.toml b/actix-server-config/Cargo.toml deleted file mode 100644 index ab2de92b..00000000 --- a/actix-server-config/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "actix-server-config" -version = "0.1.0" -authors = ["Nikolay Kim "] -description = "Actix server config utils" -homepage = "https://actix.rs" -repository = "https://github.com/actix/actix-net.git" -license = "MIT/Apache-2.0" -edition = "2018" -workspace = ".." - -[lib] -name = "actix_server_config" -path = "src/lib.rs" - -[dependencies] -actix-service = { path="../actix-service" } -futures = "0.1.25" diff --git a/actix-server-config/src/lib.rs b/actix-server-config/src/lib.rs deleted file mode 100644 index 51accad1..00000000 --- a/actix-server-config/src/lib.rs +++ /dev/null @@ -1,33 +0,0 @@ -use std::cell::Cell; -use std::net::SocketAddr; -use std::rc::Rc; - -#[derive(Debug, Clone)] -pub struct ServerConfig { - addr: SocketAddr, - secure: Rc>, -} - -impl ServerConfig { - pub fn new(addr: SocketAddr) -> Self { - ServerConfig { - addr, - secure: Rc::new(Cell::new(false)), - } - } - - /// Returns the address of the local half of this TCP server socket - pub fn local_addr(&self) -> SocketAddr { - self.addr - } - - /// Returns true if connection is secure (tls enabled) - pub fn secure(&self) -> bool { - self.secure.as_ref().get() - } - - /// Set secure flag - pub fn set_secure(&self) { - self.secure.as_ref().set(true) - } -} diff --git a/actix-server/Cargo.toml b/actix-server/Cargo.toml index 3da83ba6..ee7e1143 100644 --- a/actix-server/Cargo.toml +++ b/actix-server/Cargo.toml @@ -36,7 +36,6 @@ rust-tls = ["rustls", "tokio-rustls", "webpki", "webpki-roots"] actix-rt = "0.2.0" #actix-service = "0.3.2" actix-service = { path="../actix-service" } -actix-server-config = { path="../actix-server-config" } log = "0.4" num_cpus = "1.0" diff --git a/actix-server/src/builder.rs b/actix-server/src/builder.rs index 86433c00..f3d72dc6 100644 --- a/actix-server/src/builder.rs +++ b/actix-server/src/builder.rs @@ -150,15 +150,14 @@ impl ServerBuilder { U: net::ToSocketAddrs, { let sockets = bind_addr(addr)?; + let token = self.token.next(); + self.services.push(StreamNewService::create( + name.as_ref().to_string(), + token, + factory.clone(), + )); for lst in sockets { - let token = self.token.next(); - self.services.push(StreamNewService::create( - name.as_ref().to_string(), - token, - factory.clone(), - lst.local_addr()?, - )); self.sockets.push((token, lst)); } Ok(self) @@ -179,7 +178,6 @@ impl ServerBuilder { name.as_ref().to_string(), token, factory, - lst.local_addr()?, )); self.sockets.push((token, lst)); Ok(self) diff --git a/actix-server/src/lib.rs b/actix-server/src/lib.rs index a5ec2a72..eecc46aa 100644 --- a/actix-server/src/lib.rs +++ b/actix-server/src/lib.rs @@ -10,8 +10,6 @@ mod signals; pub mod ssl; mod worker; -pub use actix_server_config::ServerConfig; - pub use self::builder::ServerBuilder; pub use self::server::Server; pub use self::service_config::{ServiceConfig, ServiceRuntime}; diff --git a/actix-server/src/services.rs b/actix-server/src/services.rs index b69693a6..a1df1c7b 100644 --- a/actix-server/src/services.rs +++ b/actix-server/src/services.rs @@ -1,8 +1,7 @@ -use std::net::{SocketAddr, TcpStream}; +use std::net::TcpStream; use std::time::Duration; use actix_rt::spawn; -use actix_server_config::ServerConfig; use actix_service::{NewService, Service}; use futures::future::{err, ok, FutureResult}; use futures::{Future, Poll}; @@ -24,7 +23,7 @@ pub(crate) enum ServerMessage { } pub trait ServiceFactory: Send + Clone + 'static { - type NewService: NewService; + type NewService: NewService; fn create(&self) -> Self::NewService; } @@ -97,25 +96,14 @@ pub(crate) struct StreamNewService { name: String, inner: F, token: Token, - addr: SocketAddr, } impl StreamNewService where F: ServiceFactory, { - pub(crate) fn create( - name: String, - token: Token, - inner: F, - addr: SocketAddr, - ) -> Box { - Box::new(Self { - name, - token, - inner, - addr, - }) + pub(crate) fn create(name: String, token: Token, inner: F) -> Box { + Box::new(Self { name, token, inner }) } } @@ -132,17 +120,15 @@ where name: self.name.clone(), inner: self.inner.clone(), token: self.token, - addr: self.addr, }) } fn create(&self) -> Box, Error = ()>> { let token = self.token; - let config = ServerConfig::new(self.addr); Box::new( self.inner .create() - .new_service(&config) + .new_service(&()) .map_err(|_| ()) .map(move |inner| { let service: BoxedServerService = Box::new(StreamService::new(inner)); @@ -169,7 +155,7 @@ impl InternalServiceFactory for Box { impl ServiceFactory for F where F: Fn() -> T + Send + Clone + 'static, - T: NewService, + T: NewService, { type NewService = T; diff --git a/actix-server/tests/test_server.rs b/actix-server/tests/test_server.rs index 7e6be252..934e33d7 100644 --- a/actix-server/tests/test_server.rs +++ b/actix-server/tests/test_server.rs @@ -1,7 +1,7 @@ use std::{net, thread, time}; -use actix_server::{Server, ServerConfig}; -use actix_service::{fn_cfg_factory, IntoService}; +use actix_server::Server; +use actix_service::fn_service; use net2::TcpBuilder; fn unused_addr() -> net::SocketAddr { @@ -19,12 +19,7 @@ fn test_bind() { thread::spawn(move || { Server::build() - .bind("test", addr, move || { - fn_cfg_factory(move |cfg: &ServerConfig| { - assert_eq!(cfg.local_addr(), addr); - Ok::<_, ()>((|_| Ok::<_, ()>(())).into_service()) - }) - }) + .bind("test", addr, || fn_service(|_| Ok::<_, ()>(()))) .unwrap() .run() }); @@ -40,12 +35,7 @@ fn test_listen() { thread::spawn(move || { let lst = net::TcpListener::bind(addr).unwrap(); Server::build() - .listen("test", lst, move || { - fn_cfg_factory(move |cfg: &ServerConfig| { - assert_eq!(cfg.local_addr(), addr); - Ok::<_, ()>((|_| Ok::<_, ()>(())).into_service()) - }) - }) + .listen("test", lst, move || fn_service(|_| Ok::<_, ()>(()))) .unwrap() .run() });