udsipc: is_alive -> get_is_alive_func

Summary:
This makes it possible for the "is_alive" check to not require "&self" so it
does not conflict with "self.next()".

Reviewed By: zzl0

Differential Revision: D47065152

fbshipit-source-id: a5923439f153f8ea72b33831a30c06c848737f4f
This commit is contained in:
Jun Wu 2023-06-28 22:22:02 -07:00 committed by Facebook GitHub Bot
parent dd9ba613bc
commit e5f4f39e92

View File

@ -65,7 +65,7 @@ pub fn connect(path: &Path) -> anyhow::Result<NodeIpc> {
/// Similar to `std::net::Incoming` but:
/// - Owns `listener`. Does not use lifetime.
/// - Deletes the domain sockets on drop.
/// - Provides `is_alive()` to check if the socket file is still on disk.
/// - Provides `get_is_alive_func()` to check if the socket file is still on disk.
pub struct Incoming {
listener: UnixListener,
path: PathBuf,
@ -73,10 +73,12 @@ pub struct Incoming {
}
impl Incoming {
/// Check if the socket file is still on disk.
/// Get a function to check if the socket file is still on disk.
/// This can be useful to decide whether to exit in a loop.
pub fn is_alive(&self) -> bool {
self.path.exists() || self.private_path.exists()
pub fn get_is_alive_func(&self) -> Box<dyn (Fn() -> bool) + Send + Sync + 'static> {
let path = self.path.clone();
let private_path = self.private_path.clone();
Box::new(move || path.exists() || private_path.exists())
}
}