mirror of
https://github.com/fafhrd91/actix-net
synced 2025-01-30 09:22:52 +01:00
remove server config
This commit is contained in:
parent
70ead175b9
commit
a4d4770462
@ -20,7 +20,6 @@ members = [
|
||||
"actix-rt",
|
||||
"actix-service",
|
||||
"actix-server",
|
||||
"actix-server-config",
|
||||
"actix-test-server",
|
||||
"actix-utils",
|
||||
"router",
|
||||
|
@ -1,18 +0,0 @@
|
||||
[package]
|
||||
name = "actix-server-config"
|
||||
version = "0.1.0"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
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"
|
@ -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<Cell<bool>>,
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
@ -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"
|
||||
|
@ -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)
|
||||
|
@ -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};
|
||||
|
@ -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<TokioTcpStream, ServerConfig>;
|
||||
type NewService: NewService<TokioTcpStream>;
|
||||
|
||||
fn create(&self) -> Self::NewService;
|
||||
}
|
||||
@ -97,25 +96,14 @@ pub(crate) struct StreamNewService<F: ServiceFactory> {
|
||||
name: String,
|
||||
inner: F,
|
||||
token: Token,
|
||||
addr: SocketAddr,
|
||||
}
|
||||
|
||||
impl<F> StreamNewService<F>
|
||||
where
|
||||
F: ServiceFactory,
|
||||
{
|
||||
pub(crate) fn create(
|
||||
name: String,
|
||||
token: Token,
|
||||
inner: F,
|
||||
addr: SocketAddr,
|
||||
) -> Box<InternalServiceFactory> {
|
||||
Box::new(Self {
|
||||
name,
|
||||
token,
|
||||
inner,
|
||||
addr,
|
||||
})
|
||||
pub(crate) fn create(name: String, token: Token, inner: F) -> Box<InternalServiceFactory> {
|
||||
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<Future<Item = Vec<(Token, BoxedServerService)>, 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<InternalServiceFactory> {
|
||||
impl<F, T> ServiceFactory for F
|
||||
where
|
||||
F: Fn() -> T + Send + Clone + 'static,
|
||||
T: NewService<TokioTcpStream, ServerConfig>,
|
||||
T: NewService<TokioTcpStream>,
|
||||
{
|
||||
type NewService = T;
|
||||
|
||||
|
@ -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()
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user