diff --git a/actix-server/src/builder.rs b/actix-server/src/builder.rs index 0172013f..99f2754f 100644 --- a/actix-server/src/builder.rs +++ b/actix-server/src/builder.rs @@ -150,7 +150,7 @@ impl ServerBuilder { let mut srv = ConfiguredService::new(apply); for (name, lst) in cfg.services { let token = self.token.next(); - srv.stream(token, name); + srv.stream(token, name, lst.local_addr()?); self.sockets.push((token, lst)); } self.services.push(Box::new(srv)); diff --git a/actix-server/src/service_config.rs b/actix-server/src/service_config.rs index ed1713b1..20e7adc6 100644 --- a/actix-server/src/service_config.rs +++ b/actix-server/src/service_config.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use std::{fmt, io, net}; -use actix_server_config::Io; +use actix_server_config::{Io, ServerConfig}; use actix_service::{IntoNewService, NewService}; use futures::future::{join_all, Future}; use log::error; @@ -76,7 +76,7 @@ impl ServiceConfig { pub(super) struct ConfiguredService { rt: Box, - names: HashMap, + names: HashMap, services: HashMap, } @@ -89,15 +89,15 @@ impl ConfiguredService { } } - pub(super) fn stream(&mut self, token: Token, name: String) { - self.names.insert(token, name.clone()); + pub(super) fn stream(&mut self, token: Token, name: String, addr: net::SocketAddr) { + self.names.insert(token, (name.clone(), addr)); self.services.insert(name, token); } } impl InternalServiceFactory for ConfiguredService { fn name(&self, token: Token) -> &str { - &self.names[&token] + &self.names[&token].0 } fn clone_factory(&self) -> Box { @@ -117,7 +117,8 @@ impl InternalServiceFactory for ConfiguredService { // construct services let mut fut = Vec::new(); for (token, ns) in rt.services { - fut.push(ns.new_service(&()).map(move |service| (token, service))); + let config = ServerConfig::new(self.names[&token].1); + fut.push(ns.new_service(&config).map(move |service| (token, service))); } Box::new(join_all(fut).map_err(|e| { @@ -172,8 +173,8 @@ impl ServiceRuntime { pub fn service(&mut self, name: &str, service: F) where - F: IntoNewService, - T: NewService> + 'static, + F: IntoNewService, + T: NewService> + 'static, T::Future: 'static, T::Service: 'static, T::InitError: fmt::Debug, @@ -183,7 +184,7 @@ impl ServiceRuntime { self.services.insert( token.clone(), Box::new(ServiceFactory { - inner: service.into_new_service().map(|_| ()), + inner: service.into_new_service(), }), ); } else { @@ -194,6 +195,7 @@ impl ServiceRuntime { type BoxedNewService = Box< NewService< + ServerConfig, Request = (Option, ServerMessage), Response = (), Error = (), @@ -207,9 +209,9 @@ struct ServiceFactory { inner: T, } -impl NewService for ServiceFactory +impl NewService for ServiceFactory where - T: NewService, Response = ()>, + T: NewService>, T::Future: 'static, T::Service: 'static, T::Error: 'static, @@ -222,8 +224,8 @@ where type Service = BoxedServerService; type Future = Box>; - fn new_service(&self, _: &()) -> Self::Future { - Box::new(self.inner.new_service(&()).map_err(|_| ()).map(|s| { + fn new_service(&self, cfg: &ServerConfig) -> Self::Future { + Box::new(self.inner.new_service(cfg).map_err(|_| ()).map(|s| { let service: BoxedServerService = Box::new(StreamService::new(s)); service }))