1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-01-18 20:01:48 +01:00

testing: Replace net2 crate with socket2

This commit is contained in:
Yuki Okushi 2020-05-19 08:21:40 +09:00
parent 8218a098e8
commit ac6c78c476
No known key found for this signature in database
GPG Key ID: B0986C85C0E2DAA1
3 changed files with 10 additions and 6 deletions

View File

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

View File

@ -23,4 +23,4 @@ actix-server = "1.0.0"
actix-service = "1.0.0"
log = "0.4"
net2 = "0.2"
socket2 = "0.3"

View File

@ -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()
}
}