mirror of
https://github.com/fafhrd91/actix-web
synced 2025-01-18 22:01:50 +01:00
Merge pull request #1518 from JohnTitor/replace-net2
Replace deprecated `net2` crate with `socket2`
This commit is contained in:
commit
f8f5a82f40
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
* Bump minimum supported Rust version to 1.40
|
* Bump minimum supported Rust version to 1.40
|
||||||
|
|
||||||
|
* Replace deprecated `net2` crate with `socket2`
|
||||||
|
|
||||||
[#1485]: https://github.com/actix/actix-web/pull/1485
|
[#1485]: https://github.com/actix/actix-web/pull/1485
|
||||||
[#1509]: https://github.com/actix/actix-web/pull/1509
|
[#1509]: https://github.com/actix/actix-web/pull/1509
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ futures-util = { version = "0.3.5", default-features = false }
|
|||||||
fxhash = "0.2.1"
|
fxhash = "0.2.1"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
mime = "0.3"
|
mime = "0.3"
|
||||||
net2 = "0.2.33"
|
socket2 = "0.3"
|
||||||
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"] }
|
||||||
|
@ -6,8 +6,6 @@ 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;
|
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use actix_http::Protocol;
|
use actix_http::Protocol;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
@ -562,13 +560,16 @@ 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 {
|
use socket2::{Domain, Protocol, Socket, Type};
|
||||||
net::SocketAddr::V4(_) => TcpBuilder::new_v4()?,
|
let domain = match addr {
|
||||||
net::SocketAddr::V6(_) => TcpBuilder::new_v6()?,
|
net::SocketAddr::V4(_) => Domain::ipv4(),
|
||||||
|
net::SocketAddr::V6(_) => Domain::ipv6(),
|
||||||
};
|
};
|
||||||
builder.reuse_address(true)?;
|
let socket = Socket::new(domain, Type::stream(), Some(Protocol::tcp()))?;
|
||||||
builder.bind(addr)?;
|
socket.set_reuse_address(true)?;
|
||||||
Ok(builder.listen(backlog)?)
|
socket.bind(&addr.into())?;
|
||||||
|
socket.listen(backlog)?;
|
||||||
|
Ok(socket.into_tcp_listener())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "openssl")]
|
#[cfg(feature = "openssl")]
|
||||||
|
10
src/test.rs
10
src/test.rs
@ -21,10 +21,10 @@ use bytes::{Bytes, BytesMut};
|
|||||||
use futures_core::Stream;
|
use futures_core::Stream;
|
||||||
use futures_util::future::ok;
|
use futures_util::future::ok;
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
use net2::TcpBuilder;
|
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
use socket2::{Domain, Protocol, Socket, Type};
|
||||||
|
|
||||||
pub use actix_http::test::TestBuffer;
|
pub use actix_http::test::TestBuffer;
|
||||||
|
|
||||||
@ -913,10 +913,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 = TcpBuilder::new_v4().unwrap();
|
let socket = Socket::new(Domain::ipv4(), Type::stream(), Some(Protocol::tcp())).unwrap();
|
||||||
socket.bind(&addr).unwrap();
|
socket.bind(&addr.into()).unwrap();
|
||||||
socket.reuse_address(true).unwrap();
|
socket.set_reuse_address(true).unwrap();
|
||||||
let tcp = socket.to_tcp_listener().unwrap();
|
let tcp = socket.into_tcp_listener();
|
||||||
tcp.local_addr().unwrap()
|
tcp.local_addr().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
* Update `actix-connect` dependency to 2.0.0-alpha.2
|
* Update `actix-connect` dependency to 2.0.0-alpha.2
|
||||||
* Make `test_server` `async` fn.
|
* Make `test_server` `async` fn.
|
||||||
* Bump minimum supported Rust version to 1.40
|
* Bump minimum supported Rust version to 1.40
|
||||||
|
* Replace deprecated `net2` crate with `socket2`
|
||||||
|
|
||||||
## [1.0.0] - 2019-12-13
|
## [1.0.0] - 2019-12-13
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ futures-core = { version = "0.3.5", default-features = false }
|
|||||||
http = "0.2.0"
|
http = "0.2.0"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
env_logger = "0.6"
|
env_logger = "0.6"
|
||||||
net2 = "0.2"
|
socket2 = "0.3"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
sha1 = "0.6"
|
sha1 = "0.6"
|
||||||
|
@ -9,7 +9,7 @@ use awc::{error::PayloadError, ws, Client, ClientRequest, ClientResponse, Connec
|
|||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures_core::stream::Stream;
|
use futures_core::stream::Stream;
|
||||||
use http::Method;
|
use http::Method;
|
||||||
use net2::TcpBuilder;
|
use socket2::{Domain, Protocol, Socket, Type};
|
||||||
|
|
||||||
pub use actix_testing::*;
|
pub use actix_testing::*;
|
||||||
|
|
||||||
@ -104,10 +104,10 @@ pub async fn test_server<F: ServiceFactory<TcpStream>>(factory: F) -> TestServer
|
|||||||
/// 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 = TcpBuilder::new_v4().unwrap();
|
let socket = Socket::new(Domain::ipv4(), Type::stream(), Some(Protocol::tcp())).unwrap();
|
||||||
socket.bind(&addr).unwrap();
|
socket.bind(&addr.into()).unwrap();
|
||||||
socket.reuse_address(true).unwrap();
|
socket.set_reuse_address(true).unwrap();
|
||||||
let tcp = socket.to_tcp_listener().unwrap();
|
let tcp = socket.into_tcp_listener();
|
||||||
tcp.local_addr().unwrap()
|
tcp.local_addr().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,25 +1,15 @@
|
|||||||
use net2::TcpBuilder;
|
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
use std::{net, thread, time::Duration};
|
use std::{thread, time::Duration};
|
||||||
|
|
||||||
#[cfg(feature = "openssl")]
|
#[cfg(feature = "openssl")]
|
||||||
use open_ssl::ssl::SslAcceptorBuilder;
|
use open_ssl::ssl::SslAcceptorBuilder;
|
||||||
|
|
||||||
use actix_web::{web, App, HttpResponse, HttpServer};
|
use actix_web::{test, 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()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_start() {
|
async fn test_start() {
|
||||||
let addr = unused_addr();
|
let addr = test::unused_addr();
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
@ -92,7 +82,7 @@ fn ssl_acceptor() -> std::io::Result<SslAcceptorBuilder> {
|
|||||||
async fn test_start_ssl() {
|
async fn test_start_ssl() {
|
||||||
use actix_web::HttpRequest;
|
use actix_web::HttpRequest;
|
||||||
|
|
||||||
let addr = unused_addr();
|
let addr = test::unused_addr();
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user