1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-01-19 06:04:40 +01:00

Update to socket2 v0.4 (#2092)

This commit is contained in:
Thomas de Zeeuw 2021-03-19 12:17:06 +00:00 committed by GitHub
parent 351286486c
commit 9488757c29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 12 deletions

View File

@ -105,7 +105,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
serde_urlencoded = "0.7" serde_urlencoded = "0.7"
smallvec = "1.6" smallvec = "1.6"
socket2 = "0.3.16" socket2 = "0.4.0"
time = { version = "0.2.23", default-features = false, features = ["std"] } time = { version = "0.2.23", default-features = false, features = ["std"] }
tls-openssl = { package = "openssl", version = "0.10.9", optional = true } tls-openssl = { package = "openssl", version = "0.10.9", optional = true }
tls-rustls = { package = "rustls", version = "0.19.0", optional = true } tls-rustls = { package = "rustls", version = "0.19.0", optional = true }

View File

@ -42,7 +42,7 @@ bytes = "1"
futures-core = { version = "0.3.7", default-features = false } futures-core = { version = "0.3.7", default-features = false }
http = "0.2.2" http = "0.2.2"
log = "0.4" log = "0.4"
socket2 = "0.3" socket2 = "0.4"
serde = "1.0" serde = "1.0"
serde_json = "1.0" serde_json = "1.0"
slab = "0.4" slab = "0.4"

View File

@ -118,10 +118,10 @@ pub async fn test_server_with_addr<F: ServiceFactory<TcpStream>>(
/// Get first available unused address /// Get first available unused address
pub fn unused_addr() -> net::SocketAddr { pub fn unused_addr() -> net::SocketAddr {
let addr: net::SocketAddr = "127.0.0.1:0".parse().unwrap(); let addr: net::SocketAddr = "127.0.0.1:0".parse().unwrap();
let socket = Socket::new(Domain::ipv4(), Type::stream(), Some(Protocol::tcp())).unwrap(); let socket = Socket::new(Domain::IPV4, Type::STREAM, Some(Protocol::TCP)).unwrap();
socket.bind(&addr.into()).unwrap(); socket.bind(&addr.into()).unwrap();
socket.set_reuse_address(true).unwrap(); socket.set_reuse_address(true).unwrap();
let tcp = socket.into_tcp_listener(); let tcp = net::TcpListener::from(socket);
tcp.local_addr().unwrap() tcp.local_addr().unwrap()
} }

View File

@ -607,17 +607,14 @@ where
fn create_tcp_listener(addr: net::SocketAddr, backlog: u32) -> io::Result<net::TcpListener> { fn create_tcp_listener(addr: net::SocketAddr, backlog: u32) -> io::Result<net::TcpListener> {
use socket2::{Domain, Protocol, Socket, Type}; use socket2::{Domain, Protocol, Socket, Type};
let domain = match addr { let domain = Domain::for_address(addr);
net::SocketAddr::V4(_) => Domain::ipv4(), let socket = Socket::new(domain, Type::STREAM, Some(Protocol::TCP))?;
net::SocketAddr::V6(_) => Domain::ipv6(),
};
let socket = Socket::new(domain, Type::stream(), Some(Protocol::tcp()))?;
socket.set_reuse_address(true)?; socket.set_reuse_address(true)?;
socket.bind(&addr.into())?; socket.bind(&addr.into())?;
// clamp backlog to max u32 that fits in i32 range // clamp backlog to max u32 that fits in i32 range
let backlog = cmp::min(backlog, i32::MAX as u32) as i32; let backlog = cmp::min(backlog, i32::MAX as u32) as i32;
socket.listen(backlog)?; socket.listen(backlog)?;
Ok(socket.into_tcp_listener()) Ok(net::TcpListener::from(socket))
} }
#[cfg(feature = "openssl")] #[cfg(feature = "openssl")]

View File

@ -862,10 +862,10 @@ impl TestServerConfig {
/// Get first available unused address /// Get first available unused address
pub fn unused_addr() -> net::SocketAddr { pub fn unused_addr() -> net::SocketAddr {
let addr: net::SocketAddr = "127.0.0.1:0".parse().unwrap(); let addr: net::SocketAddr = "127.0.0.1:0".parse().unwrap();
let socket = Socket::new(Domain::ipv4(), Type::stream(), Some(Protocol::tcp())).unwrap(); let socket = Socket::new(Domain::IPV4, Type::STREAM, Some(Protocol::TCP)).unwrap();
socket.bind(&addr.into()).unwrap(); socket.bind(&addr.into()).unwrap();
socket.set_reuse_address(true).unwrap(); socket.set_reuse_address(true).unwrap();
let tcp = socket.into_tcp_listener(); let tcp = net::TcpListener::from(socket);
tcp.local_addr().unwrap() tcp.local_addr().unwrap()
} }