std/sys/net/connection/
mod.rs

1cfg_select! {
2    any(
3        all(target_family = "unix", not(target_os = "l4re")),
4        target_os = "windows",
5        target_os = "hermit",
6        all(target_os = "wasi", target_env = "p2"),
7        target_os = "solid_asp3",
8    ) => {
9        mod socket;
10        pub use socket::*;
11    }
12    all(target_vendor = "fortanix", target_env = "sgx") => {
13        mod sgx;
14        pub use sgx::*;
15    }
16    all(target_os = "wasi", target_env = "p1") => {
17        mod wasip1;
18        pub use wasip1::*;
19    }
20    target_os = "xous" => {
21        mod xous;
22        pub use xous::*;
23    }
24    target_os = "uefi" => {
25        mod uefi;
26        pub use uefi::*;
27    }
28    _ => {
29        mod unsupported;
30        pub use unsupported::*;
31    }
32}
33
34#[cfg_attr(
35    // Make sure that this is used on some platforms at least.
36    not(any(target_os = "linux", target_os = "windows")),
37    allow(dead_code)
38)]
39fn each_addr<A: crate::net::ToSocketAddrs, F, T>(addr: A, mut f: F) -> crate::io::Result<T>
40where
41    F: FnMut(&crate::net::SocketAddr) -> crate::io::Result<T>,
42{
43    use crate::io::Error;
44
45    let mut last_err = None;
46    for addr in addr.to_socket_addrs()? {
47        match f(&addr) {
48            Ok(l) => return Ok(l),
49            Err(e) => last_err = Some(e),
50        }
51    }
52
53    match last_err {
54        Some(err) => Err(err),
55        None => Err(Error::NO_ADDRESSES),
56    }
57}