1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-06-12 02:09:36 +00:00

test-server: Replace net2 crate with socket2

This commit is contained in:
Yuki Okushi 2020-05-19 09:25:51 +09:00
parent 74491dca59
commit 2dac9afc4e
No known key found for this signature in database
GPG key ID: B0986C85C0E2DAA1
3 changed files with 7 additions and 6 deletions

View file

@ -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

View file

@ -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"

View file

@ -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<F: ServiceFactory<TcpStream>>(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()
}