diff --git a/src/transport/multicast_server.rs b/src/transport/multicast_server.rs index 1f693566..b588b204 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 726c4b10..c47f1df0 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 f7bdc908..ddec815f 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 } }