mirror of
https://github.com/actix/actix-web.git
synced 2025-04-06 10:09:44 +00:00
replace net2
This commit is contained in:
parent
0163ece23f
commit
1531c7898d
4 changed files with 12 additions and 30 deletions
|
@ -81,7 +81,6 @@ futures = "0.3.1"
|
|||
fxhash = "0.2.1"
|
||||
log = "0.4"
|
||||
mime = "0.3"
|
||||
net2 = "0.2.33"
|
||||
socket2 = "0.3.11"
|
||||
pin-project = "0.4.6"
|
||||
regex = "1.3"
|
||||
|
|
11
src/test.rs
11
src/test.rs
|
@ -20,7 +20,6 @@ use awc::{Client, ClientRequest, ClientResponse, Connector};
|
|||
use bytes::{Bytes, BytesMut};
|
||||
use futures::future::ok;
|
||||
use futures::stream::{Stream, StreamExt};
|
||||
use net2::TcpBuilder;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Serialize;
|
||||
use serde_json;
|
||||
|
@ -831,16 +830,6 @@ impl TestServerConfig {
|
|||
}
|
||||
}
|
||||
|
||||
/// 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();
|
||||
tcp.local_addr().unwrap()
|
||||
}
|
||||
|
||||
/// Test server controller
|
||||
pub struct TestServer {
|
||||
addr: net::SocketAddr,
|
||||
|
|
|
@ -9,7 +9,6 @@ use awc::{error::PayloadError, ws, Client, ClientRequest, ClientResponse, Connec
|
|||
use bytes::Bytes;
|
||||
use futures::Stream;
|
||||
use http::Method;
|
||||
use net2::TcpBuilder;
|
||||
|
||||
pub use actix_testing::*;
|
||||
|
||||
|
@ -101,16 +100,6 @@ pub 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();
|
||||
tcp.local_addr().unwrap()
|
||||
}
|
||||
|
||||
/// Test server controller
|
||||
pub struct TestServer {
|
||||
addr: net::SocketAddr,
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use net2::TcpBuilder;
|
||||
use std::sync::mpsc;
|
||||
use std::{net, thread, time::Duration};
|
||||
|
||||
|
@ -8,12 +7,18 @@ use open_ssl::ssl::SslAcceptorBuilder;
|
|||
use actix_web::{web, App, HttpResponse, HttpServer};
|
||||
|
||||
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();
|
||||
tcp.local_addr().unwrap()
|
||||
(1025..65535).find_map(|port| {
|
||||
match net::TcpListener::bind(net::SocketAddr::new(
|
||||
net::IpAddr::V4(net::Ipv4Addr::new(127, 0, 0, 1)),
|
||||
port,
|
||||
)) {
|
||||
Ok(listener) => {
|
||||
Some(listener.local_addr())
|
||||
}
|
||||
Err(_) => None,
|
||||
}
|
||||
});
|
||||
panic!("Could not find an unused port!");
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
|
|
Loading…
Reference in a new issue