diff --git a/test-server/CHANGES.md b/test-server/CHANGES.md index 6a92d581c..1570e36d8 100644 --- a/test-server/CHANGES.md +++ b/test-server/CHANGES.md @@ -6,6 +6,7 @@ * Update `actix-connect` dependency to 2.0.0-alpha.2 * Make `test_server` `async` fn. * Bump minimum supported Rust version to 1.40 +* Replace deprecated `net2` crate with `socket2` ## [1.0.0] - 2019-12-13 diff --git a/test-server/Cargo.toml b/test-server/Cargo.toml index 8357815c9..ebfbd55cd 100644 --- a/test-server/Cargo.toml +++ b/test-server/Cargo.toml @@ -45,7 +45,7 @@ futures-core = { version = "0.3.5", default-features = false } http = "0.2.0" log = "0.4" env_logger = "0.6" -net2 = "0.2" +socket2 = "0.3" serde = "1.0" serde_json = "1.0" sha1 = "0.6" diff --git a/test-server/src/lib.rs b/test-server/src/lib.rs index 4fa0ecc17..265d9a771 100644 --- a/test-server/src/lib.rs +++ b/test-server/src/lib.rs @@ -9,7 +9,7 @@ use awc::{error::PayloadError, ws, Client, ClientRequest, ClientResponse, Connec use bytes::Bytes; use futures_core::stream::Stream; use http::Method; -use net2::TcpBuilder; +use socket2::{Domain, Protocol, Socket, Type}; pub use actix_testing::*; @@ -104,10 +104,10 @@ pub async fn test_server>(factory: F) -> TestServer /// Get first available unused address pub fn unused_addr() -> net::SocketAddr { let addr: net::SocketAddr = "127.0.0.1:0".parse().unwrap(); - let socket = TcpBuilder::new_v4().unwrap(); - socket.bind(&addr).unwrap(); - socket.reuse_address(true).unwrap(); - let tcp = socket.to_tcp_listener().unwrap(); + let socket = Socket::new(Domain::ipv4(), Type::stream(), Some(Protocol::tcp())).unwrap(); + socket.bind(&addr.into()).unwrap(); + socket.set_reuse_address(true).unwrap(); + let tcp = socket.into_tcp_listener(); tcp.local_addr().unwrap() }