mirror of https://github.com/fafhrd91/actix-net
				
				
				
			do not remove the uds socket on pause
This commit is contained in:
		
							parent
							
								
									72481313cc
								
							
						
					
					
						commit
						4ab41440ad
					
				| 
						 | 
				
			
			@ -31,7 +31,7 @@ async fn run() -> io::Result<()> {
 | 
			
		|||
    let count = Arc::new(AtomicUsize::new(0));
 | 
			
		||||
 | 
			
		||||
    let addr = ("127.0.0.1", 8080);
 | 
			
		||||
    info!("starting server on port: {}", &addr.0);
 | 
			
		||||
    info!("starting server on: {}:{}", &addr.0, &addr.1);
 | 
			
		||||
 | 
			
		||||
    // Bind socket address and start worker(s). By default, the server uses the number of physical
 | 
			
		||||
    // CPU cores as the worker count. For this reason, the closure passed to bind needs to return
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -217,6 +217,8 @@ impl Accept {
 | 
			
		|||
                        self.deregister_all(sockets);
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    self.terminate_all(sockets);
 | 
			
		||||
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -330,6 +332,10 @@ impl Accept {
 | 
			
		|||
            .for_each(|(_, info)| self.deregister_logged(info));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn terminate_all(&self, sockets: &mut[ServerSocketInfo]) {
 | 
			
		||||
        sockets.iter().for_each(|s| s.lst.terminate());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Send connection to worker and handle error.
 | 
			
		||||
    fn send_connection(&mut self, conn: Conn) -> Result<(), Conn> {
 | 
			
		||||
        let next = self.next();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -38,11 +38,28 @@ impl MioListener {
 | 
			
		|||
        match *self {
 | 
			
		||||
            MioListener::Tcp(ref lst) => lst.accept().map(|(stream, _)| MioStream::Tcp(stream)),
 | 
			
		||||
            #[cfg(unix)]
 | 
			
		||||
            MioListener::Uds(ref lst) => lst.accept().map(|(stream, _)| MioStream::Uds(stream)),
 | 
			
		||||
            MioListener::Uds(ref lst) => {
 | 
			
		||||
                lst.accept().map(|(stream, _)| MioStream::Uds(stream))
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub(crate) fn terminate(&self) {
 | 
			
		||||
        match *self {
 | 
			
		||||
            MioListener::Tcp(_) => (),
 | 
			
		||||
            #[cfg(unix)]
 | 
			
		||||
            MioListener::Uds(ref lst) => {
 | 
			
		||||
                    if let Ok(addr) = lst.local_addr() {
 | 
			
		||||
                        if let Some(path) = addr.as_pathname() {
 | 
			
		||||
                            let _ = std::fs::remove_file(path);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
impl Source for MioListener {
 | 
			
		||||
    fn register(
 | 
			
		||||
        &mut self,
 | 
			
		||||
| 
						 | 
				
			
			@ -74,17 +91,7 @@ impl Source for MioListener {
 | 
			
		|||
        match *self {
 | 
			
		||||
            MioListener::Tcp(ref mut lst) => lst.deregister(registry),
 | 
			
		||||
            #[cfg(unix)]
 | 
			
		||||
            MioListener::Uds(ref mut lst) => {
 | 
			
		||||
                let res = lst.deregister(registry);
 | 
			
		||||
 | 
			
		||||
                // cleanup file path
 | 
			
		||||
                if let Ok(addr) = lst.local_addr() {
 | 
			
		||||
                    if let Some(path) = addr.as_pathname() {
 | 
			
		||||
                        let _ = std::fs::remove_file(path);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                res
 | 
			
		||||
            }
 | 
			
		||||
            MioListener::Uds(ref mut lst) => lst.deregister(registry)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -270,4 +277,17 @@ mod tests {
 | 
			
		|||
            assert!(format!("{}", lst).contains("/tmp/sock.xxxxx"));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    #[cfg(unix)]
 | 
			
		||||
    fn uds_terminate() {
 | 
			
		||||
        let socket_path = std::path::Path::new("/tmp/sock.xxxx1");
 | 
			
		||||
        let _ = std::fs::remove_file(socket_path);
 | 
			
		||||
        if let Ok(socket) = MioUnixListener::bind(socket_path) {
 | 
			
		||||
            let listener = MioListener::Uds(socket);
 | 
			
		||||
            assert!(socket_path.exists());
 | 
			
		||||
            listener.terminate();
 | 
			
		||||
            assert!(!socket_path.exists());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue