1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use cfg_if::*;
use std::path::Path;

cfg_if! {
    if #[cfg(feature="rt-tokio")] {
        mod ipc_tokio;
        pub use ipc_tokio::*;
    } else if #[cfg(feature="rt-async-std")] {
        mod ipc_async_std;
        #[cfg_attr(windows, allow(unused_imports))]
        pub use ipc_async_std::*;
    }
}

#[allow(unused_variables)]
pub fn is_ipc_socket_path<P: AsRef<Path>>(path: P) -> bool {
    cfg_if! {
        if #[cfg(windows)] {
            let p = path.as_ref().to_path_buf().to_string_lossy().to_string().to_lowercase();
            p.starts_with(r"\\.\pipe") && path.as_ref().exists()
        } else if #[cfg(unix)] {
            use std::os::unix::fs::FileTypeExt;
            let meta = match std::fs::metadata(path) {
                Ok(v) => v,
                Err(_) => {
                    return false;
                }
            };
            meta.file_type().is_socket()
        } else {
            false
        }
    }
}