diff --git a/actix-server/src/builder.rs b/actix-server/src/builder.rs index 34288d11..f0eef5c0 100644 --- a/actix-server/src/builder.rs +++ b/actix-server/src/builder.rs @@ -112,7 +112,6 @@ impl ServerBuilder { self.max_concurrent_connections(num) } - // TODO: wtf is this for /// Stop Actix system. pub fn system_exit(mut self) -> Self { self.exit = true; @@ -162,55 +161,6 @@ impl ServerBuilder { Ok(self) } - /// Add new unix domain service to the server. - #[cfg(unix)] - pub fn bind_uds(self, name: N, addr: U, factory: F) -> io::Result - where - F: ServiceFactory, - N: AsRef, - U: AsRef, - { - // The path must not exist when we try to bind. - // Try to remove it to avoid bind error. - if let Err(e) = std::fs::remove_file(addr.as_ref()) { - // NotFound is expected and not an issue. Anything else is. - if e.kind() != std::io::ErrorKind::NotFound { - return Err(e); - } - } - - let lst = crate::socket::StdUnixListener::bind(addr)?; - self.listen_uds(name, lst, factory) - } - - /// Add new unix domain service to the server. - /// - /// Useful when running as a systemd service and a socket FD is acquired externally. - #[cfg(unix)] - pub fn listen_uds>( - mut self, - name: N, - lst: crate::socket::StdUnixListener, - factory: F, - ) -> io::Result - where - F: ServiceFactory, - { - use std::net::{IpAddr, Ipv4Addr}; - lst.set_nonblocking(true)?; - let token = self.next_token(); - let addr = StdSocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); - self.factories.push(StreamNewService::create( - name.as_ref().to_string(), - token, - factory, - addr, - )); - self.sockets - .push((token, name.as_ref().to_string(), MioListener::from(lst))); - Ok(self) - } - /// Add new service to the server. pub fn listen>( mut self, @@ -255,6 +205,56 @@ impl ServerBuilder { } } +#[cfg(unix)] +impl ServerBuilder { + /// Add new unix domain service to the server. + pub fn bind_uds(self, name: N, addr: U, factory: F) -> io::Result + where + F: ServiceFactory, + N: AsRef, + U: AsRef, + { + // The path must not exist when we try to bind. + // Try to remove it to avoid bind error. + if let Err(e) = std::fs::remove_file(addr.as_ref()) { + // NotFound is expected and not an issue. Anything else is. + if e.kind() != std::io::ErrorKind::NotFound { + return Err(e); + } + } + + let lst = crate::socket::StdUnixListener::bind(addr)?; + self.listen_uds(name, lst, factory) + } + + /// Add new unix domain service to the server. + /// + /// Useful when running as a systemd service and a socket FD is acquired externally. + pub fn listen_uds>( + mut self, + name: N, + lst: crate::socket::StdUnixListener, + factory: F, + ) -> io::Result + where + F: ServiceFactory, + { + use std::net::{IpAddr, Ipv4Addr}; + lst.set_nonblocking(true)?; + let token = self.next_token(); + let addr = StdSocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); + self.factories.push(StreamNewService::create( + name.as_ref().to_string(), + token, + factory, + addr, + )); + self.sockets + .push((token, name.as_ref().to_string(), MioListener::from(lst))); + Ok(self) + } +} + pub(super) fn bind_addr( addr: S, backlog: u32, diff --git a/actix-server/tests/test_server.rs b/actix-server/tests/test_server.rs index ee9790a5..76d99e7e 100644 --- a/actix-server/tests/test_server.rs +++ b/actix-server/tests/test_server.rs @@ -312,7 +312,6 @@ async fn test_service_restart() { h.join().unwrap().unwrap(); } -#[ignore] #[actix_rt::test] async fn worker_restart() { use actix_service::{Service, ServiceFactory};