diff --git a/network/src/channel.rs b/network/src/channel.rs index 210c4fb9db..7457fb0785 100644 --- a/network/src/channel.rs +++ b/network/src/channel.rs @@ -95,19 +95,20 @@ impl Protocols { c2s_protocol_s: mpsc::UnboundedSender<(Self, Cid)>, ) -> std::io::Result<()> { use socket2::{Domain, Socket, Type}; - use tokio::net::TcpSocket; let domain = Domain::for_address(addr); let socket2_socket = Socket::new(domain, Type::STREAM, None)?; if domain == Domain::IPV6 { socket2_socket.set_only_v6(true)? } - socket2_socket.set_nonblocking(true)?; //needed by tokio - let socket = TcpSocket::from_std_stream(socket2_socket.into()); + socket2_socket.set_nonblocking(true)?; // Needed by Tokio // See https://docs.rs/tokio/latest/tokio/net/struct.TcpSocket.html #[cfg(not(windows))] - socket.set_reuseaddr(true)?; - socket.bind(addr)?; - let listener = socket.listen(1024)?; + socket2_socket.set_reuse_address(true)?; + let socket2_addr = addr.into(); + socket2_socket.bind(&socket2_addr)?; + socket2_socket.listen(1024)?; + let std_listener: std::net::TcpListener = socket2_socket.into(); + let listener = tokio::net::TcpListener::from_std(std_listener)?; trace!(?addr, "Tcp Listener bound"); let mut end_receiver = s2s_stop_listening_r.fuse(); tokio::spawn(async move {