/// This mimics tempfile::util::create_helper but unfortunately that function is private.
This mimics tempfile::util::create_helper but unfortunately that function is private.
This mimics tempfile :: util :: create_helper but unfortunately that function is private .
fn make_temp_unix_socket() -> std::io::Result<(PathBuf, UnixListener)> {
    use rand::distributions::{Alphanumeric, DistString};
    let retries = 10;
    let prefix = "debug_agent_";
    let rand_str_length = 6;
    let suffix = ".socket";
    for _ in 0..retries {
        let rand_str = Alphanumeric.sample_string(&mut rand::thread_rng(), rand_str_length);
        let mut path = env::temp_dir().into_os_string();
        path.extend(["/".as_ref(), prefix.as_ref(), rand_str.as_ref(), suffix.as_ref()]);
        match UnixListener::bind(&path) {
            Ok(socket) => return Ok((path.into(), socket)),
            Err(e) => {
                if e.kind() == io::ErrorKind::AlreadyExists {
                    continue;
                } else {
                    return Err(e);
                }
            }
        };
    }
    Err(io::Error::new(io::ErrorKind::AlreadyExists, "cannot create temp unix socket"))
}
fn make_temp_unix_socket ( ) -> std :: io :: Result < ( PathBuf , UnixListener ) > { use rand :: distributions :: { Alphanumeric , DistString } ; let retries = 10 ; let prefix = " " ; let rand_str_length = 6 ; let suffix = " " ; for _ in 0 .. retries { let rand_str = Alphanumeric . sample_string ( & mut rand :: thread_rng ( ) , rand_str_length ) ; let mut path = env :: temp_dir ( ) . into_os_string ( ) ; path . extend ( [ " " . as_ref ( ) , prefix . as_ref ( ) , rand_str . as_ref ( ) , suffix . as_ref ( ) ] ) ; match UnixListener :: bind ( & path ) { Ok ( socket ) => return Ok ( ( path . into ( ) , socket ) ) , Err ( e ) => { if e . kind ( ) == io :: ErrorKind :: AlreadyExists { continue ; } else { return Err ( e ) ; } } } ; } Err ( io :: Error :: new ( io :: ErrorKind :: AlreadyExists , " " ) ) }
This mimics tempfile::util::create_helper but unfortunately that function is private.
This mimics tempfile :: util :: create_helper but unfortunately that function is private .