diff --git a/src/transport/multicast_server.rs b/src/transport/multicast_server.rs index 7bc92db4..4ffe04dd 100644 --- a/src/transport/multicast_server.rs +++ b/src/transport/multicast_server.rs @@ -125,7 +125,7 @@ impl MulticastServer { } pub fn close(&mut self) -> bool { - let sock = self.socket.try_write(); + let sock = self.socket.try_read(); if sock.is_err() { return false; } @@ -180,12 +180,12 @@ impl MulticastServer { pub fn stop(&mut self) -> bool { self.stop_flag.store(true, Ordering::Relaxed); - if let Some(handle) = self.thread_handle.take() { - handle.join().unwrap(); - } if !self.close() { return false; } + if let Some(handle) = self.thread_handle.take() { + handle.join().unwrap(); + } true } } diff --git a/src/transport/udp_socket.rs b/src/transport/udp_socket.rs index ebb3e4f1..753976e7 100644 --- a/src/transport/udp_socket.rs +++ b/src/transport/udp_socket.rs @@ -116,7 +116,7 @@ impl UdpSocket { Ok(()) } - pub fn close(&mut self) -> bool { + pub fn close(&self) -> bool { if self.sock.is_none() { return true; } @@ -132,7 +132,6 @@ impl UdpSocket { warn!("close {:?}", res.err()); return false; } - self.sock = None; } thread::sleep(time::Duration::from_millis(UDP_SOCKET_BIND_SLEEP_MSEC)); true diff --git a/src/transport/unicast_server.rs b/src/transport/unicast_server.rs index 0200026d..a09e099f 100644 --- a/src/transport/unicast_server.rs +++ b/src/transport/unicast_server.rs @@ -91,7 +91,7 @@ impl UnicastServer { } pub fn close(&mut self) -> bool { - let sock = self.socket.try_write(); + let sock = self.socket.try_read(); if sock.is_err() { return false; } @@ -145,12 +145,12 @@ impl UnicastServer { pub fn stop(&mut self) -> bool { self.stop_flag.store(true, Ordering::Relaxed); - if let Some(handle) = self.thread_handle.take() { - handle.join().unwrap(); - } if !self.close() { return false; } + if let Some(handle) = self.thread_handle.take() { + handle.join().unwrap(); + } true } }