1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2025-04-24 18:54:04 +00:00

Use socket2 instead of net2

This commit is contained in:
Rudolf 2020-02-03 13:40:14 +01:00
parent fe13789345
commit 0163ece23f
2 changed files with 9 additions and 7 deletions

View file

@ -82,6 +82,7 @@ fxhash = "0.2.1"
log = "0.4" log = "0.4"
mime = "0.3" mime = "0.3"
net2 = "0.2.33" net2 = "0.2.33"
socket2 = "0.3.11"
pin-project = "0.4.6" pin-project = "0.4.6"
regex = "1.3" regex = "1.3"
serde = { version = "1.0", features=["derive"] } serde = { version = "1.0", features=["derive"] }

View file

@ -6,7 +6,7 @@ use actix_http::{body::MessageBody, Error, HttpService, KeepAlive, Request, Resp
use actix_server::{Server, ServerBuilder}; use actix_server::{Server, ServerBuilder};
use actix_service::{map_config, IntoServiceFactory, Service, ServiceFactory}; use actix_service::{map_config, IntoServiceFactory, Service, ServiceFactory};
use net2::TcpBuilder; use socket2;
#[cfg(unix)] #[cfg(unix)]
use actix_http::Protocol; use actix_http::Protocol;
@ -566,13 +566,14 @@ fn create_tcp_listener(
addr: net::SocketAddr, addr: net::SocketAddr,
backlog: i32, backlog: i32,
) -> io::Result<net::TcpListener> { ) -> io::Result<net::TcpListener> {
let builder = match addr { let socket_domain = match addr {
net::SocketAddr::V4(_) => TcpBuilder::new_v4()?, net::SocketAddr::V4(_) => socket2::Domain::ipv4(),
net::SocketAddr::V6(_) => TcpBuilder::new_v6()?, net::SocketAddr::V6(_) => socket2::Domain::ipv6(),
}; };
builder.reuse_address(true)?; let socket = socket2::Socket::new(socket_domain, socket2::Type::stream(), None)?;
builder.bind(addr)?; socket.bind(&socket2::SockAddr::from(addr))?;
Ok(builder.listen(backlog)?) socket.listen(backlog)?;
Ok(socket.into_tcp_listener())
} }
#[cfg(feature = "openssl")] #[cfg(feature = "openssl")]