Skip to content

Commit

Permalink
Update UdpSocket::close()
Browse files Browse the repository at this point in the history
  • Loading branch information
cybergarage committed Aug 8, 2024
1 parent e3e59e7 commit b6d5d02
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/transport/multicast_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/transport/udp_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/transport/unicast_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit b6d5d02

Please sign in to comment.