1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-31 08:57:00 +02:00

web: Replace net2 crate with socket2

This commit is contained in:
Yuki Okushi
2020-05-19 09:34:37 +09:00
parent 2dac9afc4e
commit 9a7f93610a
5 changed files with 21 additions and 28 deletions

View File

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