mirror of
https://github.com/fafhrd91/actix-net
synced 2025-01-19 03:44:40 +01:00
Merge pull request #140 from JohnTitor/replace-net2
Replace deprecated `net2` crate with `socket2`
This commit is contained in:
commit
aad4812ba6
@ -1,5 +1,11 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
* Replace deprecated `net2` crate with `socket2`
|
||||||
|
|
||||||
## [1.0.2] - 2020-02-26
|
## [1.0.2] - 2020-02-26
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
@ -29,7 +29,7 @@ actix-utils = "1.0.4"
|
|||||||
log = "0.4"
|
log = "0.4"
|
||||||
num_cpus = "1.11"
|
num_cpus = "1.11"
|
||||||
mio = "0.6.19"
|
mio = "0.6.19"
|
||||||
net2 = "0.2"
|
socket2 = "0.3"
|
||||||
futures-channel = { version = "0.3.4", default-features = false }
|
futures-channel = { version = "0.3.4", default-features = false }
|
||||||
futures-util = { version = "0.3.4", default-features = false, features = ["sink"] }
|
futures-util = { version = "0.3.4", default-features = false, features = ["sink"] }
|
||||||
slab = "0.4"
|
slab = "0.4"
|
||||||
|
@ -12,7 +12,7 @@ use futures_util::future::ready;
|
|||||||
use futures_util::stream::FuturesUnordered;
|
use futures_util::stream::FuturesUnordered;
|
||||||
use futures_util::{ready, future::Future, FutureExt, stream::Stream, StreamExt};
|
use futures_util::{ready, future::Future, FutureExt, stream::Stream, StreamExt};
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use net2::TcpBuilder;
|
use socket2::{Domain, Protocol, Socket, Type};
|
||||||
|
|
||||||
use crate::accept::{AcceptLoop, AcceptNotify, Command};
|
use crate::accept::{AcceptLoop, AcceptNotify, Command};
|
||||||
use crate::config::{ConfiguredService, ServiceConfig};
|
use crate::config::{ConfiguredService, ServiceConfig};
|
||||||
@ -487,11 +487,13 @@ pub(super) fn bind_addr<S: net::ToSocketAddrs>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn create_tcp_listener(addr: net::SocketAddr, backlog: i32) -> io::Result<net::TcpListener> {
|
fn create_tcp_listener(addr: net::SocketAddr, backlog: i32) -> io::Result<net::TcpListener> {
|
||||||
let builder = match addr {
|
let domain = match addr {
|
||||||
net::SocketAddr::V4(_) => TcpBuilder::new_v4()?,
|
net::SocketAddr::V4(_) => Domain::ipv4(),
|
||||||
net::SocketAddr::V6(_) => TcpBuilder::new_v6()?,
|
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())
|
||||||
}
|
}
|
||||||
|
@ -5,14 +5,14 @@ use std::{net, thread, time};
|
|||||||
use actix_server::Server;
|
use actix_server::Server;
|
||||||
use actix_service::fn_service;
|
use actix_service::fn_service;
|
||||||
use futures_util::future::{lazy, ok};
|
use futures_util::future::{lazy, ok};
|
||||||
use net2::TcpBuilder;
|
use socket2::{Domain, Protocol, Socket, Type};
|
||||||
|
|
||||||
fn unused_addr() -> net::SocketAddr {
|
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,5 +1,9 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
* Replace deprecated `net2` crate with `socket2`
|
||||||
|
|
||||||
## [1.0.0] - 2019-12-11
|
## [1.0.0] - 2019-12-11
|
||||||
|
|
||||||
* Update actix-server to 1.0.0
|
* Update actix-server to 1.0.0
|
||||||
|
@ -23,4 +23,4 @@ actix-server = "1.0.0"
|
|||||||
actix-service = "1.0.0"
|
actix-service = "1.0.0"
|
||||||
|
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
net2 = "0.2"
|
socket2 = "0.3"
|
||||||
|
@ -7,7 +7,7 @@ use std::{net, thread};
|
|||||||
|
|
||||||
use actix_rt::{net::TcpStream, System};
|
use actix_rt::{net::TcpStream, System};
|
||||||
use actix_server::{Server, ServerBuilder, ServiceFactory};
|
use actix_server::{Server, ServerBuilder, ServiceFactory};
|
||||||
use net2::TcpBuilder;
|
use socket2::{Domain, Protocol, Socket, Type};
|
||||||
|
|
||||||
#[cfg(not(test))] // Work around for rust-lang/rust#62127
|
#[cfg(not(test))] // Work around for rust-lang/rust#62127
|
||||||
pub use actix_macros::test;
|
pub use actix_macros::test;
|
||||||
@ -110,10 +110,10 @@ impl TestServer {
|
|||||||
/// Get firat available unused local address
|
/// Get firat available unused local 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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user