From ac6c78c476f4cd8a8f670bf6ee9b14d313e56a47 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Tue, 19 May 2020 08:21:40 +0900 Subject: [PATCH] testing: Replace `net2` crate with `socket2` --- actix-testing/CHANGES.md | 4 ++++ actix-testing/Cargo.toml | 2 +- actix-testing/src/lib.rs | 10 +++++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/actix-testing/CHANGES.md b/actix-testing/CHANGES.md index cc37a085..96328c16 100644 --- a/actix-testing/CHANGES.md +++ b/actix-testing/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [Unreleased] + +* Replace deprecated `net2` crate with `socket2` + ## [1.0.0] - 2019-12-11 * Update actix-server to 1.0.0 diff --git a/actix-testing/Cargo.toml b/actix-testing/Cargo.toml index 4c1891c9..f30f973b 100644 --- a/actix-testing/Cargo.toml +++ b/actix-testing/Cargo.toml @@ -23,4 +23,4 @@ actix-server = "1.0.0" actix-service = "1.0.0" log = "0.4" -net2 = "0.2" +socket2 = "0.3" diff --git a/actix-testing/src/lib.rs b/actix-testing/src/lib.rs index c1e192e1..c9f6799f 100644 --- a/actix-testing/src/lib.rs +++ b/actix-testing/src/lib.rs @@ -7,7 +7,7 @@ use std::{net, thread}; use actix_rt::{net::TcpStream, System}; use actix_server::{Server, ServerBuilder, ServiceFactory}; -use net2::TcpBuilder; +use socket2::{Domain, Protocol, Socket, Type}; #[cfg(not(test))] // Work around for rust-lang/rust#62127 pub use actix_macros::test; @@ -110,10 +110,10 @@ impl TestServer { /// Get firat available unused local 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() } }