(addr: std::net::SocketAddr, reuse: bool)
| 63 | } |
| 64 | |
| 65 | pub(crate) fn new_socket(addr: std::net::SocketAddr, reuse: bool) -> Result<TcpSocket, std::io::Error> { |
| 66 | let socket = match addr { |
| 67 | std::net::SocketAddr::V4(..) => TcpSocket::new_v4()?, |
| 68 | std::net::SocketAddr::V6(..) => TcpSocket::new_v6()?, |
| 69 | }; |
| 70 | if reuse { |
| 71 | // windows has no reuse_port, but it's reuse_address |
| 72 | // almost equals to unix's reuse_port + reuse_address, |
| 73 | // though may introduce nondeterministic behavior |
| 74 | #[cfg(unix)] |
| 75 | socket.set_reuseport(true).ok(); |
| 76 | socket.set_reuseaddr(true).ok(); |
| 77 | } |
| 78 | socket.bind(addr)?; |
| 79 | Ok(socket) |
| 80 | } |
| 81 | |
| 82 | impl FramedStream { |
| 83 | pub async fn new<T: ToSocketAddrs + std::fmt::Display>( |
no outgoing calls
no test coverage detected